Update app.py
Browse files
app.py
CHANGED
@@ -16,8 +16,9 @@ async def generate_audio(text):
|
|
16 |
prebuilt_voice_config=types.PrebuiltVoiceConfig(voice_name="Puck")
|
17 |
)
|
18 |
),
|
|
|
19 |
system_instruction=types.Content(
|
20 |
-
parts=[types.Part.from_text("Repeat user input exactly without explanation")],
|
21 |
role="user"
|
22 |
),
|
23 |
)
|
@@ -29,9 +30,8 @@ async def generate_audio(text):
|
|
29 |
if data := response.data:
|
30 |
audio_data += data
|
31 |
|
32 |
-
# Save audio with proper WAV header
|
33 |
with open("output.wav", "wb") as f:
|
34 |
-
# WAV header for 24kHz 16-bit PCM
|
35 |
f.write(b'RIFF\x00\x00\x00\x00WAVEfmt \x10\x00\x00\x00\x01\x00\x01\x00\x00\x7d\x00\x00\x02\x00\x10\x00data\x00\x00\x00\x00')
|
36 |
f.write(audio_data)
|
37 |
|
@@ -39,12 +39,12 @@ async def generate_audio(text):
|
|
39 |
|
40 |
except Exception as e:
|
41 |
print(f"Error: {str(e)}")
|
42 |
-
raise
|
43 |
|
44 |
def tts(text):
|
45 |
if not text.strip():
|
46 |
return None
|
47 |
-
return asyncio.run(generate_audio(text))
|
48 |
|
49 |
iface = gr.Interface(
|
50 |
fn=tts,
|
|
|
16 |
prebuilt_voice_config=types.PrebuiltVoiceConfig(voice_name="Puck")
|
17 |
)
|
18 |
),
|
19 |
+
# Fixed Part.from_text() call with explicit text parameter
|
20 |
system_instruction=types.Content(
|
21 |
+
parts=[types.Part.from_text(text="Repeat user input exactly without explanation")],
|
22 |
role="user"
|
23 |
),
|
24 |
)
|
|
|
30 |
if data := response.data:
|
31 |
audio_data += data
|
32 |
|
33 |
+
# Save audio with proper WAV header (24kHz 16-bit PCM)
|
34 |
with open("output.wav", "wb") as f:
|
|
|
35 |
f.write(b'RIFF\x00\x00\x00\x00WAVEfmt \x10\x00\x00\x00\x01\x00\x01\x00\x00\x7d\x00\x00\x02\x00\x10\x00data\x00\x00\x00\x00')
|
36 |
f.write(audio_data)
|
37 |
|
|
|
39 |
|
40 |
except Exception as e:
|
41 |
print(f"Error: {str(e)}")
|
42 |
+
raise
|
43 |
|
44 |
def tts(text):
|
45 |
if not text.strip():
|
46 |
return None
|
47 |
+
return asyncio.run(generate_audio(text))
|
48 |
|
49 |
iface = gr.Interface(
|
50 |
fn=tts,
|