Fix Deepgram TTS to use stream_raw()
This commit is contained in:
@@ -62,29 +62,18 @@ class DeepgramTTSService(TTSService):
|
|||||||
try:
|
try:
|
||||||
await self.start_ttfb_metrics()
|
await self.start_ttfb_metrics()
|
||||||
|
|
||||||
response = await self._deepgram_client.speak.asyncrest.v("1").stream_memory(
|
response = await self._deepgram_client.speak.asyncrest.v("1").stream_raw(
|
||||||
{"text": text}, options
|
{"text": text}, options
|
||||||
)
|
)
|
||||||
|
|
||||||
await self.start_tts_usage_metrics(text)
|
await self.start_tts_usage_metrics(text)
|
||||||
yield TTSStartedFrame()
|
yield TTSStartedFrame()
|
||||||
|
|
||||||
# The response.stream_memory is already a BytesIO object
|
async for data in response.aiter_bytes():
|
||||||
audio_buffer = response.stream_memory
|
|
||||||
|
|
||||||
if audio_buffer is None:
|
|
||||||
raise ValueError("No audio data received from Deepgram")
|
|
||||||
|
|
||||||
# Read and yield the audio data in chunks
|
|
||||||
audio_buffer.seek(0) # Ensure we're at the start of the buffer
|
|
||||||
chunk_size = 1024 # Use a fixed buffer size
|
|
||||||
while True:
|
|
||||||
await self.stop_ttfb_metrics()
|
await self.stop_ttfb_metrics()
|
||||||
chunk = audio_buffer.read(chunk_size)
|
if data:
|
||||||
if not chunk:
|
yield TTSAudioRawFrame(audio=data, sample_rate=self.sample_rate, num_channels=1)
|
||||||
break
|
|
||||||
frame = TTSAudioRawFrame(audio=chunk, sample_rate=self.sample_rate, num_channels=1)
|
|
||||||
yield frame
|
|
||||||
yield TTSStoppedFrame()
|
yield TTSStoppedFrame()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user