Add English to Katakana and Romaji conversion support
This commit is contained in:
@ -2,6 +2,7 @@ import fs from "fs";
|
||||
import path from "path";
|
||||
import ffmpegPath from "ffmpeg-static";
|
||||
import { config } from "./config.js";
|
||||
import { convertEnglishWordsOnly, initializeTextConverter } from "./text-converter.js";
|
||||
|
||||
/**
|
||||
* Split text into natural chunks for TTS processing
|
||||
@ -108,12 +109,26 @@ async function generateAudioForChunk(
|
||||
chunkIndex: number,
|
||||
itemId: string,
|
||||
): Promise<string> {
|
||||
const encodedText = encodeURIComponent(chunkText);
|
||||
// Convert English words to katakana before TTS processing
|
||||
let processedText: string;
|
||||
try {
|
||||
processedText = await convertEnglishWordsOnly(chunkText);
|
||||
if (processedText !== chunkText) {
|
||||
console.log(`チャンク${chunkIndex + 1}で英語をカタカナに変換: ${itemId}`);
|
||||
console.log(`変換前: "${chunkText}"`);
|
||||
console.log(`変換後: "${processedText}"`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(`チャンク${chunkIndex + 1}の英語変換に失敗、元のテキストを使用: ${itemId}`, error);
|
||||
processedText = chunkText;
|
||||
}
|
||||
|
||||
const encodedText = encodeURIComponent(processedText);
|
||||
const queryUrl = `${config.voicevox.host}/audio_query?text=${encodedText}&speaker=${defaultVoiceStyle.styleId}`;
|
||||
const synthesisUrl = `${config.voicevox.host}/synthesis?speaker=${defaultVoiceStyle.styleId}`;
|
||||
|
||||
console.log(
|
||||
`チャンク${chunkIndex + 1}の音声クエリ開始: ${itemId} (${chunkText.length}文字)`,
|
||||
`チャンク${chunkIndex + 1}の音声クエリ開始: ${itemId} (${processedText.length}文字)`,
|
||||
);
|
||||
|
||||
const queryResponse = await fetch(queryUrl, {
|
||||
@ -252,6 +267,13 @@ export async function generateTTSWithoutQueue(
|
||||
throw new Error("Script text is required for TTS generation");
|
||||
}
|
||||
|
||||
// Initialize text converter if not already initialized
|
||||
try {
|
||||
await initializeTextConverter();
|
||||
} catch (error) {
|
||||
console.warn("テキストコンバーターの初期化に失敗しました。英語変換をスキップします:", error);
|
||||
}
|
||||
|
||||
console.log(
|
||||
`TTS生成開始: ${itemId} (試行回数: ${retryCount + 1}, ${scriptText.length}文字)`,
|
||||
);
|
||||
|
Reference in New Issue
Block a user