meandyou200175 commited on
Commit
073ef49
·
verified ·
1 Parent(s): ee0eafe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -22
app.py CHANGED
@@ -5,28 +5,31 @@ def encode_file_to_base64(file_path):
5
  with open(file_path, "rb") as file:
6
  return base64.b64encode(file.read()).decode('utf-8')
7
  def bot_audio_interface(wav):
8
- print(wav)
9
- url = "https://737e-104-199-156-254.ngrok-free.app/speech_to_speech"
10
- b64 = encode_file_to_base64(wav)
11
- data = {"b64": b64}
12
- print('1')
13
- response = requests.post(url, json=data)
14
- print('2')
15
- if response.status_code == 200:
16
- json_response = response.json()
17
- text = json_response.get("text")
18
- response_text = json_response.get("response")
19
- audio_base64 = json_response.get("audio_base64")
20
- audio_data = base64.b64decode(audio_base64)
21
- audio_path = "response_audio.wav"
22
- with open(audio_path, "wb") as audio_file:
23
- audio_file.write(audio_data)
24
- else:
25
- print('kkk')
26
- audio_path =''
27
- text=''
28
- response_text=''
29
- return audio_path, text, response_text
 
 
 
30
 
31
 
32
  with gr.Blocks() as demo:
 
5
  with open(file_path, "rb") as file:
6
  return base64.b64encode(file.read()).decode('utf-8')
7
  def bot_audio_interface(wav):
8
+ try:
9
+ print(wav)
10
+ url = "https://737e-104-199-156-254.ngrok-free.app/speech_to_speech"
11
+ b64 = encode_file_to_base64(wav)
12
+ data = {"b64": b64}
13
+ print('1')
14
+ response = requests.post(url, json=data)
15
+ print('2')
16
+ if response.status_code == 200:
17
+ json_response = response.json()
18
+ text = json_response.get("text")
19
+ response_text = json_response.get("response")
20
+ audio_base64 = json_response.get("audio_base64")
21
+ audio_data = base64.b64decode(audio_base64)
22
+ audio_path = "response_audio1.wav"
23
+ with open(audio_path, "wb") as audio_file:
24
+ audio_file.write(audio_data)
25
+ else:
26
+ print('kkk')
27
+ audio_path =''
28
+ text=''
29
+ response_text=''
30
+ return audio_path, text, response_text
31
+ except:
32
+ return 'response_audio.wav', 'text', 'response_text'
33
 
34
 
35
  with gr.Blocks() as demo: