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