Skip to content

Commit

Permalink
voicevox: init at 0.20.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TomaSajt committed Sep 30, 2024
1 parent 105a960 commit 909e9ba
Show file tree
Hide file tree
Showing 2 changed files with 190 additions and 0 deletions.
75 changes: 75 additions & 0 deletions pkgs/by-name/vo/voicevox/hardcode-paths.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
diff --git a/.env.production b/.env.production
index 5b0dcb0..5848ccd 100644
--- a/.env.production
+++ b/.env.production
@@ -4,7 +4,7 @@ VITE_DEFAULT_ENGINE_INFOS=`[
"uuid": "074fc39e-678b-4c13-8916-ffca8d505d1d",
"name": "VOICEVOX Engine",
"executionEnabled": true,
- "executionFilePath": "vv-engine/run.exe",
+ "executionFilePath": "@voicevox_engine_path@",
"executionArgs": [],
"host": "http://127.0.0.1:50021"
}
diff --git a/electron-builder.config.js b/electron-builder.config.js
index 462e6f2..10a9bff 100644
--- a/electron-builder.config.js
+++ b/electron-builder.config.js
@@ -35,19 +35,6 @@ const isMac = process.platform === "darwin";
// cf: https://k-hyoda.hatenablog.com/entry/2021/10/23/000349#%E8%BF%BD%E5%8A%A0%E5%B1%95%E9%96%8B%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E5%85%88%E3%81%AE%E8%A8%AD%E5%AE%9A
const extraFilePrefix = isMac ? "MacOS/" : "";

-const sevenZipFile = fs
- .readdirSync(path.resolve(__dirname, "build", "vendored", "7z"))
- .find(
- // Windows: 7za.exe, Linux: 7zzs, macOS: 7zz
- (fileName) => ["7za.exe", "7zzs", "7zz"].includes(fileName),
- );
-
-if (!sevenZipFile) {
- throw new Error(
- "7z binary file not found. Run `node ./build/download7z.js` first.",
- );
-}
-
/** @type {import("electron-builder").Configuration} */
const builderOptions = {
beforeBuild: async () => {
@@ -88,14 +75,6 @@ const builderOptions = {
from: "build/README.txt",
to: extraFilePrefix + "README.txt",
},
- {
- from: VOICEVOX_ENGINE_DIR,
- to: path.join(extraFilePrefix, "vv-engine"),
- },
- {
- from: path.resolve(__dirname, "build", "vendored", "7z", sevenZipFile),
- to: extraFilePrefix + sevenZipFile,
- },
],
// electron-builder installer
productName: "VOICEVOX",
diff --git a/src/backend/electron/manager/vvppManager.ts b/src/backend/electron/manager/vvppManager.ts
index 6aa17b6..b8b52b7 100644
--- a/src/backend/electron/manager/vvppManager.ts
+++ b/src/backend/electron/manager/vvppManager.ts
@@ -196,16 +196,8 @@ export class VvppManager {

const args = ["x", "-o" + outputDir, archiveFile, "-t" + format];

- let sevenZipPath = import.meta.env.VITE_7Z_BIN_NAME;
- if (!sevenZipPath) {
- throw new Error("7z path is not defined");
- }
- if (import.meta.env.PROD) {
- sevenZipPath = path.join(
- path.dirname(app.getPath("exe")),
- sevenZipPath,
- );
- }
+ const sevenZipPath = `@sevenzip_path@`;
+
log.log(
"Spawning 7z:",
sevenZipPath,
115 changes: 115 additions & 0 deletions pkgs/by-name/vo/voicevox/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
lib,
stdenv,
buildNpmPackage,
fetchFromGitHub,
replaceVars,
makeDesktopItem,
copyDesktopItems,
makeWrapper,
electron,
_7zz,
voicevox-engine,
}:

buildNpmPackage rec {
pname = "voicevox";
version = "0.20.0";

src = fetchFromGitHub {
owner = "VOICEVOX";
repo = "voicevox";
rev = "refs/tags/${version}";
hash = "sha256-05WTecNc1xxe7SGDPZbLtRELNghFkMTqI4pkX4PsVWI=";
};

patches = [
(replaceVars ./hardcode-paths.patch {
sevenzip_path = lib.getExe _7zz;
voicevox_engine_path = lib.getExe voicevox-engine;
})
];

postPatch = ''
substituteInPlace package.json \
--replace-fail "999.999.999" "${version}" \
--replace-fail "postinstall" "_postinstall"
'';

npmDepsHash = "sha256-g3avCj3S96qYPAyGXn4yvrZ4gteJld+g4eV4aRtv/3g=";

nativeBuildInputs =
[
makeWrapper
]
++ lib.optionals stdenv.hostPlatform.isLinux [
copyDesktopItems
];

env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";

# disable code signing on Darwin
env.CSC_IDENTITY_AUTO_DISCOVERY = "false";

buildPhase = ''
runHook preBuild
VITE_TARGET=electron npm exec vite build
cp -r ${electron.dist} electron-dist
chmod -R u+w electron-dist
npm exec electron-builder -- \
--dir \
--config electron-builder.config.js \
-c.electronDist=electron-dist \
-c.electronVersion=${electron.version}
runHook postBuild
'';

installPhase = ''
runHook preInstall
${lib.optionalString stdenv.hostPlatform.isLinux ''
install -Dm644 public/icon.png $out/share/icons/hicolor/256x256/apps/voicevox.png
mkdir -p $out/share/voicevox
cp -r dist_electron/*-unpacked/{locales,resources{,.pak}} $out/share/voicevox
makeWrapper ${lib.getExe electron} $out/bin/voicevox \
--add-flags $out/share/voicevox/resources/app.asar \
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" \
--inherit-argv0
''}
${lib.optionalString stdenv.hostPlatform.isDarwin ''
mkdir -p $out/Applications
cp -r dist_electron/mac*/VOICEVOX.app $out/Applications
makeWrapper $out/Applications/VOICEVOX.app/Contents/MacOS/VOICEVOX $out/bin/voicevox
''}
runHook postInstall
'';

desktopItems = [
(makeDesktopItem {
name = "voicevox";
exec = "voicevox";
icon = "voicevox";
desktopName = "VOICEVOX";
categories = [ "AudioVideo" ];
mimeTypes = [ "application/x-voicevox" ];
})
];

meta = {
changelog = "https://github.com/VOICEVOX/voicevox/releases/tag/${version}";
description = "Editor for the VOICEVOX speech synthesis software";
homepage = "https://github.com/VOICEVOX/voicevox";
license = lib.licenses.lgpl3Only;
mainProgram = "voicevox";
maintainers = with lib.maintainers; [ tomasajt ];
platforms = electron.meta.platforms;
};
}

0 comments on commit 909e9ba

Please sign in to comment.