tts에.플레이하도록 수정
This commit is contained in:
@@ -449,7 +449,7 @@ namespace Supertonic.WinForms
|
||||
|
||||
}
|
||||
|
||||
public (float[] wav, float[] duration) Call(string text, string lang, Style style, int totalStep, float speed = 1.05f, float silenceDuration = 0.3f)
|
||||
public (float[] wav, float[] duration) Call(string text, string lang, Style style, int totalStep, float speed = 1.05f, float silenceDuration = 0.3f, float initialSilenceDuration = 0.5f)
|
||||
{
|
||||
if (style.TtlShape[0] != 1)
|
||||
{
|
||||
@@ -461,14 +461,22 @@ namespace Supertonic.WinForms
|
||||
var wavCat = new List<float>();
|
||||
float durCat = 0.0f;
|
||||
|
||||
// Add initial silence to prevent cutting off the start of the audio
|
||||
if (initialSilenceDuration > 0)
|
||||
{
|
||||
int initialSilenceLen = (int)(initialSilenceDuration * SampleRate);
|
||||
wavCat.AddRange(new float[initialSilenceLen]);
|
||||
durCat += initialSilenceDuration;
|
||||
}
|
||||
|
||||
foreach (var chunk in textList)
|
||||
{
|
||||
var (wav, duration) = _Infer(new List<string> { chunk }, new List<string> { lang }, style, totalStep, speed);
|
||||
|
||||
if (wavCat.Count == 0)
|
||||
if (wavCat.Count == 0 || (wavCat.Count == (int)(initialSilenceDuration * SampleRate) && initialSilenceDuration > 0))
|
||||
{
|
||||
wavCat.AddRange(wav);
|
||||
durCat = duration[0];
|
||||
durCat += duration[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -762,7 +770,24 @@ namespace Supertonic.WinForms
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void PlayWavFile(string filename)
|
||||
{
|
||||
if (!File.Exists(filename)) return;
|
||||
|
||||
try
|
||||
{
|
||||
using (var player = new System.Media.SoundPlayer(filename))
|
||||
{
|
||||
player.Play();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error playing WAV file: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
@@ -55,6 +55,9 @@ namespace Supertonic.WinForms
|
||||
Helper.WriteWavFile(outputPath, result.wav, _tts.SampleRate);
|
||||
Log($"Saved: {outputPath}");
|
||||
|
||||
// Play the generated WAV file immediately
|
||||
Helper.PlayWavFile(outputPath);
|
||||
|
||||
MessageBox.Show($"Synthesis completed successfully!\nSaved to: {outputPath}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user