Update app.py
Browse files
app.py
CHANGED
@@ -16,6 +16,8 @@ default_lang = "en"
|
|
16 |
engines = { default_lang: Model(default_lang) }
|
17 |
|
18 |
def transcribe(audio):
|
|
|
|
|
19 |
lang = "en"
|
20 |
model = engines[lang]
|
21 |
text = model.stt_file(audio)[0]
|
@@ -83,13 +85,17 @@ def models(text, model="Llama 3B Service", seed=42):
|
|
83 |
return output
|
84 |
|
85 |
async def respond(audio, model, seed):
|
|
|
|
|
86 |
user = transcribe(audio)
|
|
|
|
|
87 |
reply = models(user, model, seed)
|
88 |
communicate = edge_tts.Communicate(reply, voice="en-US-ChristopherNeural")
|
89 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
90 |
tmp_path = tmp_file.name
|
91 |
await communicate.save(tmp_path)
|
92 |
-
|
93 |
|
94 |
# Supported languages for seamless-expressive
|
95 |
LANGUAGE_CODES = {
|
@@ -105,6 +111,9 @@ def translate_speech(audio_file, target_language):
|
|
105 |
"""
|
106 |
Translate input speech (audio file) to the specified target language.
|
107 |
"""
|
|
|
|
|
|
|
108 |
language_code = LANGUAGE_CODES[target_language]
|
109 |
output_file = "translated_audio.wav"
|
110 |
|
@@ -122,10 +131,10 @@ def translate_speech(audio_file, target_language):
|
|
122 |
|
123 |
if os.path.exists(output_file):
|
124 |
print(f"File created successfully: {output_file}")
|
|
|
125 |
else:
|
126 |
print(f"File not found: {output_file}")
|
127 |
-
|
128 |
-
return output_file
|
129 |
|
130 |
DESCRIPTION = """ # <center><b>Hello, I am Optimus Prime your personal AI voice assistant</b></center>"""
|
131 |
|
|
|
16 |
engines = { default_lang: Model(default_lang) }
|
17 |
|
18 |
def transcribe(audio):
|
19 |
+
if audio is None:
|
20 |
+
return ""
|
21 |
lang = "en"
|
22 |
model = engines[lang]
|
23 |
text = model.stt_file(audio)[0]
|
|
|
85 |
return output
|
86 |
|
87 |
async def respond(audio, model, seed):
|
88 |
+
if audio is None:
|
89 |
+
return None
|
90 |
user = transcribe(audio)
|
91 |
+
if not user:
|
92 |
+
return None
|
93 |
reply = models(user, model, seed)
|
94 |
communicate = edge_tts.Communicate(reply, voice="en-US-ChristopherNeural")
|
95 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
96 |
tmp_path = tmp_file.name
|
97 |
await communicate.save(tmp_path)
|
98 |
+
return tmp_path
|
99 |
|
100 |
# Supported languages for seamless-expressive
|
101 |
LANGUAGE_CODES = {
|
|
|
111 |
"""
|
112 |
Translate input speech (audio file) to the specified target language.
|
113 |
"""
|
114 |
+
if audio_file is None:
|
115 |
+
return None
|
116 |
+
|
117 |
language_code = LANGUAGE_CODES[target_language]
|
118 |
output_file = "translated_audio.wav"
|
119 |
|
|
|
131 |
|
132 |
if os.path.exists(output_file):
|
133 |
print(f"File created successfully: {output_file}")
|
134 |
+
return output_file
|
135 |
else:
|
136 |
print(f"File not found: {output_file}")
|
137 |
+
return None
|
|
|
138 |
|
139 |
DESCRIPTION = """ # <center><b>Hello, I am Optimus Prime your personal AI voice assistant</b></center>"""
|
140 |
|