salomonsky commited on
Commit
376b54f
·
verified ·
1 Parent(s): 17ea6ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -12
app.py CHANGED
@@ -3,9 +3,8 @@ import base64
3
  import io
4
  from huggingface_hub import InferenceClient
5
  from gtts import gTTS
6
- from audiorecorder import audiorecorder
7
  import speech_recognition as sr
8
- from pydub import AudioSegment
9
 
10
  pre_prompt_text = "You are a behavioral AI, your answers should be brief, stoic and humanistic."
11
 
@@ -74,23 +73,18 @@ def generate(audio_text, history, temperature=None, max_new_tokens=512, top_p=0.
74
  response += response_token.token.text
75
 
76
  response = ' '.join(response.split()).replace('</s>', '')
77
- audio_file = text_to_speech(response, speed=1.3)
78
  return response, audio_file
79
 
80
- def text_to_speech(text, speed=1.3):
81
- tts = gTTS(text=text, lang='es-ES-Wavenet-B')
82
  audio_fp = io.BytesIO()
83
  tts.write_to_fp(audio_fp)
84
  audio_fp.seek(0)
85
- audio = AudioSegment.from_file(audio_fp, format="mp3")
86
- modified_speed_audio = audio.speedup(playback_speed=speed)
87
- modified_audio_fp = io.BytesIO()
88
- modified_speed_audio.export(modified_audio_fp, format="mp3")
89
- modified_audio_fp.seek(0)
90
- return modified_audio_fp
91
 
92
  def main():
93
- audio_data = audiorecorder("Push to Talk", "Stop Recording...")
94
 
95
  if not audio_data.empty():
96
  st.audio(audio_data.export().read(), format="audio/wav")
 
3
  import io
4
  from huggingface_hub import InferenceClient
5
  from gtts import gTTS
6
+ import audiorecorder
7
  import speech_recognition as sr
 
8
 
9
  pre_prompt_text = "You are a behavioral AI, your answers should be brief, stoic and humanistic."
10
 
 
73
  response += response_token.token.text
74
 
75
  response = ' '.join(response.split()).replace('</s>', '')
76
+ audio_file = text_to_speech(response)
77
  return response, audio_file
78
 
79
+ def text_to_speech(text):
80
+ tts = gTTS(text=text, lang='es')
81
  audio_fp = io.BytesIO()
82
  tts.write_to_fp(audio_fp)
83
  audio_fp.seek(0)
84
+ return audio_fp
 
 
 
 
 
85
 
86
  def main():
87
+ audio_data = audiorecorder.audiorecorder("Push to Talk", "Stop Recording...")
88
 
89
  if not audio_data.empty():
90
  st.audio(audio_data.export().read(), format="audio/wav")