frogcho123 commited on
Commit
4adb977
·
1 Parent(s): f161250

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -1,17 +1,15 @@
1
  import gradio as gr
 
2
  import whisper
3
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
4
  from gtts import gTTS
5
  import soundfile as sf
6
- import scipy.io.wavfile as wav
7
  import os
8
 
9
  def translate_speech_to_speech(input_audio):
10
  # Save the input audio to a temporary file
11
- if isinstance(input_audio, tuple):
12
- input_audio = input_audio[0]
13
- input_file = "input_audio.wav"
14
- sf.write(input_file, input_audio, 44100)
15
 
16
  # Language detection and translation code from the first code snippet
17
  model = whisper.load_model("base")
@@ -48,8 +46,8 @@ def translate_speech_to_speech(input_audio):
48
 
49
  title = "Speech-to-Speech Translator"
50
 
51
- input_audio = gr.inputs.Audio(source="microphone", type="numpy")
52
- output_audio = gr.outputs.Audio(type="numpy")
53
 
54
  stt_demo = gr.Interface(
55
  fn=translate_speech_to_speech,
@@ -60,5 +58,5 @@ stt_demo = gr.Interface(
60
  )
61
 
62
  if __name__ == "__main__":
63
- stt_demo.launch()
64
 
 
1
  import gradio as gr
2
+ from gradio import components
3
  import whisper
4
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
5
  from gtts import gTTS
6
  import soundfile as sf
 
7
  import os
8
 
9
  def translate_speech_to_speech(input_audio):
10
  # Save the input audio to a temporary file
11
+ input_file = "input_audio" + os.path.splitext(input_audio.name)[1]
12
+ sf.write(input_file, input_audio[0], 44100)
 
 
13
 
14
  # Language detection and translation code from the first code snippet
15
  model = whisper.load_model("base")
 
46
 
47
  title = "Speech-to-Speech Translator"
48
 
49
+ input_audio = components.InputComponent(source="microphone", type="numpy")
50
+ output_audio = components.OutputComponent(type="numpy")
51
 
52
  stt_demo = gr.Interface(
53
  fn=translate_speech_to_speech,
 
58
  )
59
 
60
  if __name__ == "__main__":
61
+ stt_demo.launch(share=True)
62