Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/2039_sequence…
Browse files Browse the repository at this point in the history
…r_selectable_edit_mode
  • Loading branch information
romot-co committed Nov 16, 2024
2 parents 0025f78 + 7c39bcd commit 0d30a95
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 26 deletions.
12 changes: 7 additions & 5 deletions src/backend/electron/manager/RuntimeInfoManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
};
}),
Expand Down
15 changes: 15 additions & 0 deletions src/domain/japanese/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
18 changes: 18 additions & 0 deletions src/domain/url.ts
Original file line number Diff line number Diff line change
@@ -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"が空文字でも"/"を付けるので手動で結合する。
}
17 changes: 1 addition & 16 deletions src/sing/domain.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { calculateHash } from "./utility";
import { convertLongVowel } from "@/domain/japanese";
import { convertLongVowel, moraPattern } from "@/domain/japanese";
import {
Note,
Phrase,
Expand Down Expand Up @@ -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",
);

/**
* 文字列をモーラと非モーラに分割する。長音は展開される。連続する非モーラはまとめる。
* 例:"カナー漢字" -> ["カ", "ナ", "ア", "漢字"]
Expand Down
12 changes: 7 additions & 5 deletions src/store/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ProxyStoreState, ProxyStoreTypes, EditorAudioQuery } from "./type";
import { createPartialStore } from "./vuex";
import { createEngineUrl } from "@/domain/url";
import {
IEngineConnectorFactory,
OpenAPIEngineConnectorFactory,
Expand All @@ -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) =>
Expand Down

0 comments on commit 0d30a95

Please sign in to comment.