public async Task <string> CreateAsync(string voiceText, VoiceSetting setting, string showText) { string time = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss fffffff"); string wavOutPath = Path.GetFullPath(Path.Combine(profile.AudioOutPath, time + ".wav")); string exoOutPath = Path.GetFullPath(Path.Combine(profile.AudioOutPath, time + ".exo")); // 以前と内容が被っていた場合 if (oldVoiceText != null && oldVoiceText == voiceText) { if (oldShowText == showText && oldExoOutPath != "") { return(oldExoOutPath); } oldShowText = showText; oldExoOutPath = exoOutPath; createExo(exoOutPath, setting.ExoTemplate, showText, oldWavOutPath, oldVoiceTime, setting); return(exoOutPath); } var voiceTime = await createWavAsync(wavOutPath, setting, voiceText); createExo(exoOutPath, setting.ExoTemplate, showText, wavOutPath, voiceTime, setting); oldShowText = showText; oldWavOutPath = wavOutPath; oldVoiceText = voiceText; oldExoOutPath = exoOutPath; oldVoiceTime = voiceTime; return(exoOutPath); }
// 生成されたwavの長さ(ミリ秒)を返す private async Task <int> createWavAsync(string filePath, VoiceSetting setting, string voiceText) { // SofTalk.exe に音声を生成させる // AquesTalk10 かそうでないかで分岐 if (setting.SoftalkLibrary != 11) { Process.Start( profile.SoftalkPath, string.Format( "/T:{0} /U:{1} /V:{2} /O:{3} /S:{4} /R:\"{5}\" /W:{6}", new object[] { setting.SoftalkLibrary, setting.SoftalkVoiceID, setting.SoftalkVolume, setting.SoftalkPitch, setting.SoftalkSpeed, filePath, voiceText } ) ); } else { Process.Start( profile.SoftalkPath, string.Format( "/T:{0} /U:{1} /V:{2} /O:{3} /S:{4} /J:{5} /K:{6} /L:{7} /R:\"{8}\" /W:{9}", new object[] { setting.SoftalkLibrary, setting.SoftalkVoiceID, setting.SoftalkVolume, setting.SoftalkPitch, setting.SoftalkSpeed, setting.A10Pitch, setting.A10Accent, setting.A10Pitch2, filePath, voiceText } ) ); } FileStream wavFs; // 音声が完成するまで待つ while (true) { await Task.Delay(50); try { wavFs = new FileStream(filePath, FileMode.Open); break; } catch { } } // 音声の長さを調べる var wav = new WaveFileReader(wavFs); var voiceTime = (int)wav.TotalTime.TotalMilliseconds; wav.Dispose(); wavFs.Dispose(); return(voiceTime); }
private void createExo(string filePath, string template, string showText, string wavOutPath, int voiceTime, VoiceSetting voiceSetting) { // 表示テキストをExoで利用できるようにする var exoShowText = BitConverter.ToString(Encoding.Unicode.GetBytes(showText)) .Replace("-", "") .ToLower() .PadRight(4096, '0'); var exoVoiceTime = (int)((voiceTime + voiceSetting.AudioOffset) * (profile.AviutlFps / 1000f)); // 一応0以下にはしない if (exoVoiceTime < 1) { exoVoiceTime = 1; } var exoStr = string.Format(template, exoShowText, wavOutPath, exoVoiceTime); using (var exoFs = new StreamWriter(filePath, false, Encoding.GetEncoding("shift_jis"))) { exoFs.Write(exoStr); } }