From 8bf37e21c5a4e907eeee6000214fef73101a28ee Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Sat, 16 Nov 2024 22:06:20 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Refactor:=20moraPattern=E3=82=92domain/japa?= =?UTF-8?q?nese=E3=81=AB=E7=A7=BB=E5=8B=95=20(#2350)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/japanese/index.ts | 15 +++++++++++++++ src/sing/domain.ts | 17 +---------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/domain/japanese/index.ts b/src/domain/japanese/index.ts index e9a90bdfad..44c606e9f1 100644 --- a/src/domain/japanese/index.ts +++ b/src/domain/japanese/index.ts @@ -40,3 +40,18 @@ export const convertLongVowel = (text: string): string => { .replace(/(?<=[ん]ー*)ー/g, "ん") .replace(/(?<=[っ]ー*)ー/g, "っ"); }; + +// 参考:https://github.com/VOICEVOX/voicevox_core/blob/0848630d81ae3e917c6ff2038f0b15bbd4270702/crates/voicevox_core/src/user_dict/word.rs#L83-L90 +export const moraPattern = new RegExp( + "(?:" + + "[イ][ェ]|[ヴ][ャュョ]|[トド][ゥ]|[テデ][ィャュョ]|[デ][ェ]|[クグ][ヮ]|" + // rule_others + "[キシチニヒミリギジビピ][ェャュョ]|" + // rule_line_i + "[ツフヴ][ァ]|[ウスツフヴズ][ィ]|[ウツフヴ][ェォ]|" + // rule_line_u + "[ァ-ヴー]|" + // rule_one_mora + "[い][ぇ]|[ゃゅょ]|[とど][ぅ]|[てで][ぃゃゅょ]|[で][ぇ]|[くぐ][ゎ]|" + // rule_others + "[きしちにひみりぎじびぴ][ぇゃゅょ]|" + // rule_line_i + "[つふゔ][ぁ]|[うすつふゔず][ぃ]|[うつふゔ][ぇぉ]|" + // rule_line_u + "[ぁ-ゔー]" + // rule_one_mora + ")", + "g", +); diff --git a/src/sing/domain.ts b/src/sing/domain.ts index 95d12ab1e7..faf7230042 100644 --- a/src/sing/domain.ts +++ b/src/sing/domain.ts @@ -1,5 +1,5 @@ import { calculateHash } from "./utility"; -import { convertLongVowel } from "@/domain/japanese"; +import { convertLongVowel, moraPattern } from "@/domain/japanese"; import { Note, Phrase, @@ -534,21 +534,6 @@ export function applyPitchEdit( } } -// 参考:https://github.com/VOICEVOX/voicevox_core/blob/0848630d81ae3e917c6ff2038f0b15bbd4270702/crates/voicevox_core/src/user_dict/word.rs#L83-L90 -export const moraPattern = new RegExp( - "(?:" + - "[イ][ェ]|[ヴ][ャュョ]|[トド][ゥ]|[テデ][ィャュョ]|[デ][ェ]|[クグ][ヮ]|" + // rule_others - "[キシチニヒミリギジビピ][ェャュョ]|" + // rule_line_i - "[ツフヴ][ァ]|[ウスツフヴズ][ィ]|[ウツフヴ][ェォ]|" + // rule_line_u - "[ァ-ヴー]|" + // rule_one_mora - "[い][ぇ]|[ゃゅょ]|[とど][ぅ]|[てで][ぃゃゅょ]|[で][ぇ]|[くぐ][ゎ]|" + // rule_others - "[きしちにひみりぎじびぴ][ぇゃゅょ]|" + // rule_line_i - "[つふゔ][ぁ]|[うすつふゔず][ぃ]|[うつふゔ][ぇぉ]|" + // rule_line_u - "[ぁ-ゔー]" + // rule_one_mora - ")", - "g", -); - /** * 文字列をモーラと非モーラに分割する。長音は展開される。連続する非モーラはまとめる。 * 例:"カナー漢字" -> ["カ", "ナ", "ア", "漢字"] From 7c39bcd77d22024981d4b301641102103e694263 Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Sat, 16 Nov 2024 22:15:38 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Refactor:=20=E3=82=A8=E3=83=B3=E3=82=B8?= =?UTF-8?q?=E3=83=B3=E3=81=AE=20URL=20=E3=82=92=E7=B5=84=E3=81=BF=E7=AB=8B?= =?UTF-8?q?=E3=81=A6=E3=82=8B=E9=83=A8=E5=88=86=E3=82=92=E9=96=A2=E6=95=B0?= =?UTF-8?q?=E3=81=AB=E5=88=87=E3=82=8A=E5=87=BA=E3=81=99=20(#2351)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../electron/manager/RuntimeInfoManager.ts | 12 +++++++----- src/domain/url.ts | 18 ++++++++++++++++++ src/store/proxy.ts | 12 +++++++----- 3 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 src/domain/url.ts diff --git a/src/backend/electron/manager/RuntimeInfoManager.ts b/src/backend/electron/manager/RuntimeInfoManager.ts index 732e0fa341..ddefc10f2d 100644 --- a/src/backend/electron/manager/RuntimeInfoManager.ts +++ b/src/backend/electron/manager/RuntimeInfoManager.ts @@ -8,6 +8,7 @@ import log from "electron-log/main"; import type { AltPortInfos } from "@/store/type"; import { EngineId, EngineInfo } from "@/type/preload"; import { writeFileSafely } from "@/backend/electron/fileHelper"; +import { createEngineUrl } from "@/domain/url"; /** * ランタイム情報書き出しに必要なEngineInfo @@ -85,13 +86,14 @@ export class RuntimeInfoManager { const altPort: string | undefined = this.altportInfos[engineInfo.uuid]; const port = altPort ?? engineInfo.defaultPort; - // NOTE: URLを正規化する - const url = new URL(`${engineInfo.protocol}//${engineInfo.hostname}`); - url.port = port; return { uuid: engineInfo.uuid, - // NOTE: URLインターフェースは"pathname"が空文字でも"/"を付けるので手動で結合する。 - url: `${url.origin}${engineInfo.pathname}`, + url: createEngineUrl({ + protocol: engineInfo.protocol, + hostname: engineInfo.hostname, + port, + pathname: engineInfo.pathname, + }), name: engineInfo.name, }; }), diff --git a/src/domain/url.ts b/src/domain/url.ts new file mode 100644 index 0000000000..723c9ab31f --- /dev/null +++ b/src/domain/url.ts @@ -0,0 +1,18 @@ +/** エンジンのURLを構成するパラメータ */ +export type EngineUrlParams = { + protocol: string; // `http:`など + hostname: string; // `example.com`など + port: string; // `50021`など。空文字列もありえる。 + pathname: string; // `/engine`など。空文字列もありえる。 +}; + +/** + * URLを構成するパラメータから、VOICEVOXエディタが初期から想定しているURL文字列を組み立てる。 + * pathnameが空文字の場合は末尾にスラッシュを付与しない、などがビルトインのURLクラスと異なる。 + */ +export function createEngineUrl(params: EngineUrlParams) { + const { protocol, hostname, port, pathname } = params; + const url = new URL(`${protocol}//${hostname}`); // NOTE: URLを正規化する + url.port = port; + return `${url.origin}${pathname}`; // NOTE: URLインターフェースは"pathname"が空文字でも"/"を付けるので手動で結合する。 +} diff --git a/src/store/proxy.ts b/src/store/proxy.ts index 82342bd632..283e2e9fd2 100644 --- a/src/store/proxy.ts +++ b/src/store/proxy.ts @@ -1,5 +1,6 @@ import { ProxyStoreState, ProxyStoreTypes, EditorAudioQuery } from "./type"; import { createPartialStore } from "./vuex"; +import { createEngineUrl } from "@/domain/url"; import { IEngineConnectorFactory, OpenAPIEngineConnectorFactory, @@ -22,12 +23,13 @@ const proxyStoreCreator = (_engineFactory: IEngineConnectorFactory) => { const altPort: string | undefined = state.altPortInfos[engineId]; const port = altPort ?? engineInfo.defaultPort; - // NOTE: URLを正規化する - const url = new URL(`${engineInfo.protocol}//${engineInfo.hostname}`); - url.port = port; - // NOTE: URLインターフェースは"pathname"が空文字でも"/"を付けるので手動で結合する。 const instance = _engineFactory.instance( - `${url.origin}${engineInfo.pathname}`, + createEngineUrl({ + protocol: engineInfo.protocol, + hostname: engineInfo.hostname, + port, + pathname: engineInfo.pathname, + }), ); return Promise.resolve({ invoke: (v) => (arg) =>