오디오재생함수추가
This commit is contained in:
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Supertonic
|
||||
{
|
||||
@@ -11,13 +12,14 @@ namespace Supertonic
|
||||
{
|
||||
public bool UseGpu { get; set; } = false;
|
||||
public string OnnxDir { get; set; } = "assets/onnx";
|
||||
public string BaseDir { get; set; } = "";
|
||||
public int TotalStep { get; set; } = 5;
|
||||
public float Speed { get; set; } = 1.05f;
|
||||
public int NTest { get; set; } = 4;
|
||||
public List<string> VoiceStyle { get; set; } = new List<string> { "assets/voice_styles/M1.json" };
|
||||
public List<string> VoiceStyle { get; set; } = new List<string> { "assets/voice_styles/M2.json" };
|
||||
public List<string> Text { get; set; } = new List<string>
|
||||
{
|
||||
"This morning, I took a walk in the park, and the sound of the birds and the breeze was so pleasant that I stopped for a long time just to listen."
|
||||
"hello , 안녕하세요"
|
||||
};
|
||||
public string SaveDir { get; set; } = "results";
|
||||
public bool Batch { get; set; } = false;
|
||||
@@ -58,13 +60,16 @@ namespace Supertonic
|
||||
case "--save-dir" when i + 1 < args.Length:
|
||||
result.SaveDir = args[++i];
|
||||
break;
|
||||
case "--base-dir" when i + 1 < args.Length:
|
||||
result.BaseDir = args[++i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("=== TTS Inference with ONNX Runtime (C#) ===\n");
|
||||
|
||||
@@ -86,10 +91,15 @@ namespace Supertonic
|
||||
int bsz = voiceStylePaths.Count;
|
||||
|
||||
// --- 2. Load Text to Speech --- //
|
||||
var textToSpeech = Helper.LoadTextToSpeech(parsedArgs.OnnxDir, parsedArgs.UseGpu);
|
||||
var onnxdir = System.IO.Path.Combine(parsedArgs.BaseDir, parsedArgs.OnnxDir);
|
||||
var textToSpeech = Helper.LoadTextToSpeech(onnxdir, parsedArgs.UseGpu);
|
||||
Console.WriteLine();
|
||||
|
||||
// --- 3. Load Voice Style --- //
|
||||
for(int i = 0; i < voiceStylePaths.Count;i++)
|
||||
{
|
||||
voiceStylePaths[i] = Path.Combine(parsedArgs.BaseDir, voiceStylePaths[i]);
|
||||
}
|
||||
var style = Helper.LoadVoiceStyle(voiceStylePaths, verbose: true);
|
||||
|
||||
// --- 4. Synthesize speech --- //
|
||||
@@ -114,6 +124,8 @@ namespace Supertonic
|
||||
Directory.CreateDirectory(saveDir);
|
||||
}
|
||||
|
||||
var playbackTasks = new List<Task>();
|
||||
|
||||
for (int b = 0; b < bsz; b++)
|
||||
{
|
||||
string fname = $"{Helper.SanitizeFilename(textList[b], 20)}_{n + 1}.wav";
|
||||
@@ -125,7 +137,16 @@ namespace Supertonic
|
||||
string outputPath = Path.Combine(saveDir, fname);
|
||||
Helper.WriteWavFile(outputPath, wavOut, textToSpeech.SampleRate);
|
||||
Console.WriteLine($"Saved: {outputPath}");
|
||||
|
||||
// 비동기로 오디오 재생 (파일 저장과 동시에)
|
||||
Console.WriteLine($"Playing audio [{b + 1}/{bsz}]...");
|
||||
var playTask = Helper.PlayAudioAsync(wavOut, textToSpeech.SampleRate);
|
||||
playbackTasks.Add(playTask);
|
||||
}
|
||||
|
||||
// 모든 재생이 완료될 때까지 대기
|
||||
await Task.WhenAll(playbackTasks);
|
||||
Console.WriteLine("Playback completed.");
|
||||
}
|
||||
|
||||
Console.WriteLine("\n=== Synthesis completed successfully! ===");
|
||||
|
||||
Reference in New Issue
Block a user