Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import torch
|
| 3 |
import scipy.io.wavfile as wavfile
|
| 4 |
from transformers import pipeline
|
| 5 |
|
|
@@ -8,27 +7,30 @@ asr = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
|
| 8 |
tts = pipeline("text-to-speech", model="facebook/mms-tts-hin")
|
| 9 |
|
| 10 |
def speech_to_speech(audio):
|
|
|
|
|
|
|
|
|
|
| 11 |
# Speech → Text
|
| 12 |
-
result = asr(
|
| 13 |
text = result["text"]
|
| 14 |
|
| 15 |
# Text → Speech (Hindi voice)
|
| 16 |
speech = tts(text)
|
| 17 |
|
| 18 |
-
# Save
|
| 19 |
wavfile.write("output.wav", speech["sampling_rate"], speech["audio"])
|
| 20 |
|
| 21 |
return text, "output.wav"
|
| 22 |
|
| 23 |
demo = gr.Interface(
|
| 24 |
fn=speech_to_speech,
|
| 25 |
-
inputs=gr.Audio(type="
|
| 26 |
outputs=[
|
| 27 |
gr.Textbox(label="Recognized Text"),
|
| 28 |
gr.Audio(label="Hindi Speech Output")
|
| 29 |
],
|
| 30 |
title="Speech to Speech AI (Hindi)",
|
| 31 |
-
description="Speak into the mic, AI listens and replies in Hindi
|
| 32 |
)
|
| 33 |
|
| 34 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import scipy.io.wavfile as wavfile
|
| 3 |
from transformers import pipeline
|
| 4 |
|
|
|
|
| 7 |
tts = pipeline("text-to-speech", model="facebook/mms-tts-hin")
|
| 8 |
|
| 9 |
def speech_to_speech(audio):
|
| 10 |
+
# audio = (sample_rate, numpy_array)
|
| 11 |
+
sample_rate, audio_data = audio
|
| 12 |
+
|
| 13 |
# Speech → Text
|
| 14 |
+
result = asr(audio_data, sampling_rate=sample_rate)
|
| 15 |
text = result["text"]
|
| 16 |
|
| 17 |
# Text → Speech (Hindi voice)
|
| 18 |
speech = tts(text)
|
| 19 |
|
| 20 |
+
# Save output
|
| 21 |
wavfile.write("output.wav", speech["sampling_rate"], speech["audio"])
|
| 22 |
|
| 23 |
return text, "output.wav"
|
| 24 |
|
| 25 |
demo = gr.Interface(
|
| 26 |
fn=speech_to_speech,
|
| 27 |
+
inputs=gr.Audio(type="numpy", label="Speak here"),
|
| 28 |
outputs=[
|
| 29 |
gr.Textbox(label="Recognized Text"),
|
| 30 |
gr.Audio(label="Hindi Speech Output")
|
| 31 |
],
|
| 32 |
title="Speech to Speech AI (Hindi)",
|
| 33 |
+
description="Speak into the mic, AI listens and replies in Hindi"
|
| 34 |
)
|
| 35 |
|
| 36 |
demo.launch()
|