Update app.py
Browse files
app.py
CHANGED
|
@@ -39,6 +39,23 @@ def bot_audio_interface(wav):
|
|
| 39 |
audio_path = "response_audio1.wav"
|
| 40 |
with open(audio_path, "wb") as audio_file:
|
| 41 |
audio_file.write(audio_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
return audio_path, text, response_text
|
| 43 |
except:
|
| 44 |
return 'final_output.wav', 'text', 'response_text'
|
|
|
|
| 39 |
audio_path = "response_audio1.wav"
|
| 40 |
with open(audio_path, "wb") as audio_file:
|
| 41 |
audio_file.write(audio_data)
|
| 42 |
+
else:
|
| 43 |
+
print('switch2')
|
| 44 |
+
url = "https://0537-35-247-65-73.ngrok-free.app/speech_to_speech"
|
| 45 |
+
b64 = encode_file_to_base64(wav)
|
| 46 |
+
data = {"b64": b64}
|
| 47 |
+
print('1')
|
| 48 |
+
response = requests.post(url, json=data)
|
| 49 |
+
print('2')
|
| 50 |
+
if response.status_code == 200:
|
| 51 |
+
json_response = response.json()
|
| 52 |
+
text = json_response.get("text")
|
| 53 |
+
response_text = json_response.get("response")
|
| 54 |
+
audio_base64 = json_response.get("audio_base64")
|
| 55 |
+
audio_data = base64.b64decode(audio_base64)
|
| 56 |
+
audio_path = "response_audio1.wav"
|
| 57 |
+
with open(audio_path, "wb") as audio_file:
|
| 58 |
+
audio_file.write(audio_data)
|
| 59 |
return audio_path, text, response_text
|
| 60 |
except:
|
| 61 |
return 'final_output.wav', 'text', 'response_text'
|