Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from gtts import gTTS
|
| 4 |
+
|
| 5 |
+
# Load the Whisper model for speech-to-text
|
| 6 |
+
pipe = pipeline(model="openai/whisper-small")
|
| 7 |
+
|
| 8 |
+
# Load the text generation model
|
| 9 |
+
text_pipe = pipeline("text2text-generation", model="google/byt5-small")
|
| 10 |
+
|
| 11 |
+
def transcribe(audio):
|
| 12 |
+
# Transcribe the audio to text
|
| 13 |
+
text = pipe(audio)["text"]
|
| 14 |
+
|
| 15 |
+
# Generate a response from the transcribed text
|
| 16 |
+
lm_response = text_pipe(text)[0]["generated_text"]
|
| 17 |
+
|
| 18 |
+
# Convert the response text to speech
|
| 19 |
+
tts = gTTS(lm_response, lang='ko')
|
| 20 |
+
|
| 21 |
+
# Save the generated audio
|
| 22 |
+
out_audio = "output_audio.mp3"
|
| 23 |
+
tts.save(out_audio)
|
| 24 |
+
|
| 25 |
+
return out_audio
|
| 26 |
+
|
| 27 |
+
# Create the Gradio interface
|
| 28 |
+
iface = gr.Interface(
|
| 29 |
+
fn=transcribe,
|
| 30 |
+
inputs=gr.Audio(type="filepath"),
|
| 31 |
+
outputs=gr.Audio(type="filepath"),
|
| 32 |
+
title="Whisper Small Glaswegian",
|
| 33 |
+
description="Realtime demo for Glaswegian speech recognition using a fine-tuned Whisper small model."
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
# Launch the interface
|
| 37 |
+
iface.launch(share=True)
|