Nathan Franklin commited on
Commit
8cf49b6
·
1 Parent(s): 65e32e0

add edge-tts capability for text to speech

Browse files
Files changed (2) hide show
  1. app.py +14 -1
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,8 +1,19 @@
1
  import gradio as gr
2
  from faster_whisper import WhisperModel
 
 
 
3
 
4
  model = WhisperModel("tiny", compute_type="float32")
5
 
 
 
 
 
 
 
 
 
6
  def generate_response(
7
  language_level, buddy_personality,
8
  language_choice, user_query_audio,
@@ -29,8 +40,10 @@ def generate_response(
29
  # Convert llm response to audio
30
  # Return None to reset user input audio and
31
  # llm response + user inputs in chatbot_history object to be displayed
 
 
32
 
33
- return None, chatbot_history, user_query_audio
34
 
35
  with gr.Blocks() as demo:
36
 
 
1
  import gradio as gr
2
  from faster_whisper import WhisperModel
3
+ import edge_tts
4
+ import tempfile
5
+ import asyncio
6
 
7
  model = WhisperModel("tiny", compute_type="float32")
8
 
9
+ # Text-to-speech function
10
+ async def text_to_speech(text, voice):
11
+ communicate = edge_tts.Communicate(text, voice)
12
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
13
+ tmp_path = tmp_file.name
14
+ await communicate.save(tmp_path)
15
+ return tmp_path, None
16
+
17
  def generate_response(
18
  language_level, buddy_personality,
19
  language_choice, user_query_audio,
 
40
  # Convert llm response to audio
41
  # Return None to reset user input audio and
42
  # llm response + user inputs in chatbot_history object to be displayed
43
+ voice_short_name = "en-US-BrianNeural"
44
+ bot_message_audio, warning = asyncio.run(text_to_speech(text=bot_message, voice=voice_short_name))
45
 
46
+ return None, chatbot_history, bot_message_audio
47
 
48
  with gr.Blocks() as demo:
49
 
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  faster-whisper==1.0.3
2
- gradio==4.42.0
 
 
1
  faster-whisper==1.0.3
2
+ gradio==4.42.0
3
+ edge-tts==6.1.12