Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -24,7 +24,9 @@ app = FastAPI(
|
|
24 |
# ------------------------------------------------------------------------------
|
25 |
# Create one pipeline instance for the entire app.
|
26 |
model = KModel() # Initialize KModel
|
27 |
-
|
|
|
|
|
28 |
|
29 |
|
30 |
# ------------------------------------------------------------------------------
|
@@ -118,7 +120,7 @@ def tts_streaming(text: str, voice: str = "af_heart", speed: float = 1.0, format
|
|
118 |
yield header
|
119 |
|
120 |
# Stream audio chunks from the pipeline.
|
121 |
-
for audio_chunk in
|
122 |
if audio_chunk is not None and audio_chunk.numel() > 0:
|
123 |
if format.lower() == "wav":
|
124 |
yield audio_chunk_to_pcm_bytes(audio_chunk)
|
@@ -127,11 +129,10 @@ def tts_streaming(text: str, voice: str = "af_heart", speed: float = 1.0, format
|
|
127 |
else:
|
128 |
raise ValueError(f"Unsupported audio format: {format}")
|
129 |
|
130 |
-
media_type = "audio/wav" if format.lower() == "wav" else "audio/opus"
|
131 |
|
132 |
return StreamingResponse(
|
133 |
audio_chunk_generator(),
|
134 |
-
media_type=
|
135 |
headers={"Cache-Control": "no-cache"},
|
136 |
)
|
137 |
|
|
|
24 |
# ------------------------------------------------------------------------------
|
25 |
# Create one pipeline instance for the entire app.
|
26 |
model = KModel() # Initialize KModel
|
27 |
+
stream_pipeline = StreamKPipeline(lang_code="a", model=model, chunk_size=2) # Initialize StreamKPipeline, passing the model
|
28 |
+
pipeline = KPipeline(lang_code="a", model=model) # Initialize KPipeline, passing the model
|
29 |
+
|
30 |
|
31 |
|
32 |
# ------------------------------------------------------------------------------
|
|
|
120 |
yield header
|
121 |
|
122 |
# Stream audio chunks from the pipeline.
|
123 |
+
for audio_chunk in stream_pipeline(text=text, voice=voice, speed=speed):
|
124 |
if audio_chunk is not None and audio_chunk.numel() > 0:
|
125 |
if format.lower() == "wav":
|
126 |
yield audio_chunk_to_pcm_bytes(audio_chunk)
|
|
|
129 |
else:
|
130 |
raise ValueError(f"Unsupported audio format: {format}")
|
131 |
|
|
|
132 |
|
133 |
return StreamingResponse(
|
134 |
audio_chunk_generator(),
|
135 |
+
media_type="audio/wav",
|
136 |
headers={"Cache-Control": "no-cache"},
|
137 |
)
|
138 |
|