Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
@@ -22,22 +22,7 @@ def split_text(text: str, words_per_chunk: int = 20):
|
|
22 |
words = text.split()
|
23 |
return [' '.join(words[i:i + words_per_chunk]) for i in range(0, len(words), words_per_chunk)]
|
24 |
|
25 |
-
|
26 |
-
def generate_audio_chunks(text: str, language: str, chunk_size: int = 20) -> Generator[bytes, None, None]:
|
27 |
-
if tts.is_multi_lingual and not language:
|
28 |
-
raise ValueError("Language must be specified for multi-lingual models.")
|
29 |
-
|
30 |
-
text_chunks = split_text(text, chunk_size)
|
31 |
-
|
32 |
-
for idx, chunk in enumerate(text_chunks):
|
33 |
-
# Generate audio for each chunk and yield as bytes
|
34 |
-
tts.tts_to_file(
|
35 |
-
text=chunk,
|
36 |
-
file_path=f"out_{idx}.wav",
|
37 |
-
speaker_wav=FIXED_SPEAKER_WAV,
|
38 |
-
language=language
|
39 |
-
)
|
40 |
-
yield f"out_{idx}.wav"
|
41 |
|
42 |
@app.post("/generate-audio/")
|
43 |
async def generate_audio(
|
@@ -49,10 +34,19 @@ async def generate_audio(
|
|
49 |
|
50 |
# StreamingResponse to stream audio chunks
|
51 |
def audio_stream():
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
return StreamingResponse(audio_stream(), media_type="audio/wav")
|
|
|
22 |
words = text.split()
|
23 |
return [' '.join(words[i:i + words_per_chunk]) for i in range(0, len(words), words_per_chunk)]
|
24 |
|
25 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
@app.post("/generate-audio/")
|
28 |
async def generate_audio(
|
|
|
34 |
|
35 |
# StreamingResponse to stream audio chunks
|
36 |
def audio_stream():
|
37 |
+
if tts.is_multi_lingual and not language:
|
38 |
+
raise ValueError("Language must be specified for multi-lingual models.")
|
39 |
+
|
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 |
+
tts.tts_to_file(
|
45 |
+
text=chunk,
|
46 |
+
file_path=f"out_{idx}.wav",
|
47 |
+
speaker_wav=FIXED_SPEAKER_WAV,
|
48 |
+
language=language
|
49 |
+
)
|
50 |
+
yield f"out_{idx}.wav"
|
51 |
+
|
52 |
return StreamingResponse(audio_stream(), media_type="audio/wav")
|