Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
@@ -40,40 +40,19 @@ async def generate_audio(
|
|
40 |
text_chunks = split_text(text, 20)
|
41 |
|
42 |
for idx, chunk in enumerate(text_chunks):
|
43 |
-
print(chunk)
|
44 |
# Generate audio for each chunk and yield as bytes
|
|
|
45 |
tts.tts_to_file(
|
46 |
text=chunk,
|
47 |
-
file_path=
|
48 |
speaker_wav=FIXED_SPEAKER_WAV,
|
49 |
language=language
|
50 |
)
|
51 |
-
print(
|
52 |
# Read the file content and yield as binary
|
53 |
-
with open(f"
|
54 |
yield audio_file.read()
|
55 |
-
|
|
|
56 |
|
57 |
return StreamingResponse(audio_stream(), media_type="audio/wav")
|
58 |
-
|
59 |
-
@app.post("/generate_audio_normal/")
|
60 |
-
async def generate_audio_normal(
|
61 |
-
text: str = Query(..., description="The input text to convert to speech."),
|
62 |
-
language: str = Query("en", description="Language code for TTS (e.g., 'en' for English).")
|
63 |
-
):
|
64 |
-
|
65 |
-
text_chunks = split_text(text, 20)
|
66 |
-
|
67 |
-
for idx, chunk in enumerate(text_chunks):
|
68 |
-
print(chunk)
|
69 |
-
# Generate audio for each chunk and yield as bytes
|
70 |
-
tts.tts_to_file(
|
71 |
-
text=chunk,
|
72 |
-
file_path=f"out_{idx}.wav",
|
73 |
-
speaker_wav=FIXED_SPEAKER_WAV,
|
74 |
-
language=language
|
75 |
-
)
|
76 |
-
print(f"out_{idx}.wav")
|
77 |
-
return f"out_{idx}.wav"
|
78 |
-
|
79 |
-
#return StreamingResponse(audio_stream(), media_type="audio/wav")
|
|
|
40 |
text_chunks = split_text(text, 20)
|
41 |
|
42 |
for idx, chunk in enumerate(text_chunks):
|
|
|
43 |
# Generate audio for each chunk and yield as bytes
|
44 |
+
output_file = f"out_{idx}.wav"
|
45 |
tts.tts_to_file(
|
46 |
text=chunk,
|
47 |
+
file_path=output_file,
|
48 |
speaker_wav=FIXED_SPEAKER_WAV,
|
49 |
language=language
|
50 |
)
|
51 |
+
print(output_file)
|
52 |
# Read the file content and yield as binary
|
53 |
+
with open(f"chunk_{idx}.wav", "rb") as audio_file:
|
54 |
yield audio_file.read()
|
55 |
+
# Optionally delete the file after streaming
|
56 |
+
os.remove(output_file)
|
57 |
|
58 |
return StreamingResponse(audio_stream(), media_type="audio/wav")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|