sachin
commited on
Commit
·
7ee697f
1
Parent(s):
7e9e8cc
test
Browse files- src/server/main.py +5 -1
src/server/main.py
CHANGED
@@ -341,11 +341,15 @@ async def synthesize_speech(tts_manager: TTSManager, text: str, ref_audio_name:
|
|
341 |
logger.info(f"Synthesizing speech for text: {text[:50]}... with ref_audio: {ref_audio_name}")
|
342 |
sample_rate, audio_data = load_audio_from_url(ref_audio_url)
|
343 |
|
344 |
-
|
|
|
345 |
sf.write(temp_audio.name, audio_data, samplerate=sample_rate, format='WAV')
|
346 |
temp_audio.flush()
|
347 |
audio = await asyncio.to_thread(tts_manager.synthesize, text, temp_audio.name, ref_text)
|
348 |
|
|
|
|
|
|
|
349 |
if audio.dtype == np.int16:
|
350 |
audio = audio.astype(np.float32) / 32768.0
|
351 |
buffer = io.BytesIO()
|
|
|
341 |
logger.info(f"Synthesizing speech for text: {text[:50]}... with ref_audio: {ref_audio_name}")
|
342 |
sample_rate, audio_data = load_audio_from_url(ref_audio_url)
|
343 |
|
344 |
+
# Use synchronous context manager and run synthesis in a thread
|
345 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_audio:
|
346 |
sf.write(temp_audio.name, audio_data, samplerate=sample_rate, format='WAV')
|
347 |
temp_audio.flush()
|
348 |
audio = await asyncio.to_thread(tts_manager.synthesize, text, temp_audio.name, ref_text)
|
349 |
|
350 |
+
# Clean up temporary file
|
351 |
+
os.unlink(temp_audio.name)
|
352 |
+
|
353 |
if audio.dtype == np.int16:
|
354 |
audio = audio.astype(np.float32) / 32768.0
|
355 |
buffer = io.BytesIO()
|