-
Hi,
I see that the partialClipCallback is called, but no peep from my speakers. I've tried a few variations but nothing seemed to work. Can you help me? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
ps. It might be a nice sample to add to your github, as I expect this is what many people would like to do |
Beta Was this translation helpful? Give feedback.
-
Solved it! This works: public async Task TextToOut(string text)
{
_voice = (await _api.VoicesEndpoint.GetAllVoicesAsync()).FirstOrDefault();
// Setup BufferedWaveProvider with the correct format
var waveFormat = new WaveFormat(24000, 16, 1); // Assuming mono channel; adjust if necessary
var bufferedWaveProvider = new BufferedWaveProvider(waveFormat)
{
BufferDuration = TimeSpan.FromSeconds(10), // Set a buffer duration to avoid overflow
DiscardOnBufferOverflow = true // Discard excess data if the buffer is full
};
var waveOut = new WaveOutEvent();
waveOut.Init(bufferedWaveProvider); // Initialize waveOut with BufferedWaveProvider
// Start playback immediately
waveOut.Play();
// *** Get the partial voice clips *** //
var voiceClip = await _api.TextToSpeechEndpoint.TextToSpeechAsync(
text,
_voice,
null,
null,
OutputFormat.PCM_24000,
null,
partialClipCallback: async (partialClip) =>
{
// Write the incoming data to the buffered wave provider
bufferedWaveProvider.AddSamples(partialClip.ClipData.ToArray(), 0, partialClip.ClipData.Length);
});
// Handle playback stopped event, if needed
waveOut.PlaybackStopped += (sender, args) =>
{
waveOut.Dispose();
};
} |
Beta Was this translation helpful? Give feedback.
Solved it! This works: