Jofthomas HF staff commited on
Commit
71528c1
1 Parent(s): bbcae98

Update TextGen/router.py

Browse files
Files changed (1) hide show
  1. TextGen/router.py +3 -1
TextGen/router.py CHANGED
@@ -127,6 +127,7 @@ def determine_vocie_from_npc(npc,genre):
127
  else:
128
  return "./voices/narator_out.wav"
129
 
 
130
  @app.post("/generate_wav")
131
  async def generate_wav(message: VoiceMessage):
132
  try:
@@ -134,7 +135,7 @@ async def generate_wav(message: VoiceMessage):
134
  audio_file_pth = handle_file(voice)
135
 
136
  # Generator function to yield audio chunks
137
- def audio_stream():
138
  result = tts_client.predict(
139
  prompt=message.input,
140
  language=message.language,
@@ -148,6 +149,7 @@ async def generate_wav(message: VoiceMessage):
148
  )
149
  for sampling_rate, audio_chunk in result:
150
  yield audio_chunk.tobytes()
 
151
 
152
  # Return the generated audio as a streaming response
153
  return StreamingResponse(audio_stream(), media_type="audio/wav")
 
127
  else:
128
  return "./voices/narator_out.wav"
129
 
130
+
131
  @app.post("/generate_wav")
132
  async def generate_wav(message: VoiceMessage):
133
  try:
 
135
  audio_file_pth = handle_file(voice)
136
 
137
  # Generator function to yield audio chunks
138
+ async def audio_stream():
139
  result = tts_client.predict(
140
  prompt=message.input,
141
  language=message.language,
 
149
  )
150
  for sampling_rate, audio_chunk in result:
151
  yield audio_chunk.tobytes()
152
+ await asyncio.sleep(0) # Yield control to the event loop
153
 
154
  # Return the generated audio as a streaming response
155
  return StreamingResponse(audio_stream(), media_type="audio/wav")