Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 無視テキスト関連のバグ修正 #1428

Merged
merged 3 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions src/store/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ import {
convertLongVowel,
createKanaRegex,
currentDateString,
skipMemoText,
skipReadingPart,
skipWritingPart,
extractExportText,
extractYomiText,
} from "./utility";
import { convertAudioQueryFromEditorToEngine } from "./proxy";
import { createPartialStore } from "./vuex";
Expand Down Expand Up @@ -1362,17 +1361,18 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
}

if (state.savingSetting.exportText) {
const text = extractExportText(state.audioItems[audioKey].text);
const textBlob = ((): Blob => {
if (!encoding || encoding === "UTF-8") {
const bom = new Uint8Array([0xef, 0xbb, 0xbf]);
return new Blob([bom, state.audioItems[audioKey].text], {
return new Blob([bom, text], {
type: "text/plain;charset=UTF-8",
});
}
const sjisArray = Encoding.convert(
Encoding.stringToCode(state.audioItems[audioKey].text),
{ to: "SJIS", type: "arraybuffer" }
);
const sjisArray = Encoding.convert(Encoding.stringToCode(text), {
to: "SJIS",
type: "arraybuffer",
});
return new Blob([new Uint8Array(sjisArray)], {
type: "text/plain;charset=Shift_JIS",
});
Expand Down Expand Up @@ -1555,7 +1555,7 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
return { result: "WRITE_ERROR", path: filePath };
}
labs.push(lab);
texts.push(state.audioItems[audioKey].text);
texts.push(extractExportText(state.audioItems[audioKey].text));
// 最終音素の終了時刻を取得する
const splitLab = lab.split(" ");
labOffset = Number(splitLab[splitLab.length - 2]);
Expand Down Expand Up @@ -1601,10 +1601,9 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
if (state.savingSetting.exportText) {
const textBlob = ((): Blob => {
const text = texts.join("\n");
const skippedText = skipReadingPart(skipMemoText(text));
if (!encoding || encoding === "UTF-8") {
const bom = new Uint8Array([0xef, 0xbb, 0xbf]);
return new Blob([bom, skippedText], {
return new Blob([bom, text], {
type: "text/plain;charset=UTF-8",
});
}
Expand Down Expand Up @@ -1694,8 +1693,8 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
? characters.get(`${engineId}:${styleId}`) + ","
: "";

const skippedText = skipReadingPart(
skipMemoText(state.audioItems[audioKey].text)
const skippedText = extractExportText(
state.audioItems[audioKey].text
);
texts.push(speakerName + skippedText);
}
Expand Down Expand Up @@ -2002,7 +2001,7 @@ export const audioCommandStore = transformCommandStore(
const engineId = state.audioItems[audioKey].voice.engineId;
const styleId = state.audioItems[audioKey].voice.styleId;
const query = state.audioItems[audioKey].query;
const skippedText = skipWritingPart(skipMemoText(text));
const skippedText = extractYomiText(text);

try {
if (query !== undefined) {
Expand Down
13 changes: 9 additions & 4 deletions src/store/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,21 @@ function replaceTag(
return result;
}

export function skipReadingPart(text: string): string {
export function extractExportText(text: string): string {
return skipReadingPart(skipMemoText(text));
}
export function extractYomiText(text: string): string {
return skipWritingPart(skipMemoText(text));
}
function skipReadingPart(text: string): string {
// テキスト内の全ての{漢字|かんじ}パターンを探し、漢字部分だけを残す
return text.replace(/\{([^|]*)\|([^}]*)\}/g, "$1");
}

export function skipWritingPart(text: string): string {
function skipWritingPart(text: string): string {
// テキスト内の全ての{漢字|かんじ}パターンを探し、かんじ部分だけを残す
return text.replace(/\{([^|]*)\|([^}]*)\}/g, "$2");
}
export function skipMemoText(targettext: string): string {
function skipMemoText(targettext: string): string {
// []をスキップ
const resolvedText = targettext.replace(/\[.*?\]/g, "");
return resolvedText;
Expand Down