From 7fa48498254e73fc6e2daa714c040bae2af4c515 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Thu, 23 Nov 2023 20:42:14 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=E8=AA=AD=E7=82=B9=E5=91=A8=E3=82=8A?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.ts | 5 ++++- providers/synthesis.ts | 45 +++++++++++++++++++----------------------- store.ts | 3 ++- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/main.ts b/main.ts index a648038..9bedc77 100644 --- a/main.ts +++ b/main.ts @@ -27,13 +27,16 @@ if (store.enginePath != undefined) { store.enginePath = undefined; } else { console.log(`Starting the engine at ${store.enginePath}...`); - new Deno.Command( + const process = new Deno.Command( store.enginePath, { stdout: "inherit", stderr: "inherit", }, ).spawn(); + self.addEventListener("unload", () => { + process.kill(); + }); } } else { console.log("No engine path, not starting the engine."); diff --git a/providers/synthesis.ts b/providers/synthesis.ts index 365b0cc..bd50cc8 100644 --- a/providers/synthesis.ts +++ b/providers/synthesis.ts @@ -83,38 +83,33 @@ const prosodyToAccentPhrases = (prosody: Prosody) => { const accentPhrasesToProsody = (accentPhrases: AccentPhrase[]) => { return accentPhrases.map((accentPhrase) => { const detail = []; - let hasPause = false; accentPhrase.moras.forEach((mora, i) => { - if (mora.text === "、") { - hasPause = true; + let phoneme; + if (mora.consonant && mora.consonant.length > 0) { + phoneme = `${mora.consonant}-${mora.vowel}`; } else { - let phoneme; - if (mora.consonant && mora.consonant.length > 0) { - phoneme = `${mora.consonant}-${mora.vowel}`; - } else { - phoneme = mora.vowel; - } - - let accent = 0; - if ( - i === accentPhrase.accent - 1 || - (i !== 0 && i <= accentPhrase.accent - 1) - ) { - accent = 1; - } + phoneme = mora.vowel; + } - detail.push({ - hira: wanakana.toHiragana( - mora.text, - ), - phoneme, - accent, - }); + let accent = 0; + if ( + i === accentPhrase.accent - 1 || + (i !== 0 && i <= accentPhrase.accent - 1) + ) { + accent = 1; } + + detail.push({ + hira: wanakana.toHiragana( + mora.text, + ), + phoneme, + accent, + }); }); - if (hasPause) { + if (accentPhrase.pause_mora) { detail.push({ hira: "、", phoneme: "_", diff --git a/store.ts b/store.ts index 5aa9ddf..ec169b4 100644 --- a/store.ts +++ b/store.ts @@ -45,5 +45,6 @@ export const getOrAppendSpeaker = async ( }; export const saveStore = async () => { - await Deno.writeTextFile(filePath, JSON.stringify(store)); + await Deno.writeTextFile(filePath + ".tmp", JSON.stringify(store)); + await Deno.rename(filePath + ".tmp", filePath); };