Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
import speech_recognition as sr
|
| 2 |
import difflib
|
| 3 |
import gradio as gr
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Step 1: Transcribe the audio file
|
| 6 |
def transcribe_audio(audio):
|
|
@@ -57,6 +59,12 @@ def compare_texts(reference_text, transcribed_text):
|
|
| 57 |
|
| 58 |
return output
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
# Gradio Interface Function
|
| 61 |
def gradio_function(paragraph, audio):
|
| 62 |
# Transcribe the audio
|
|
@@ -80,5 +88,17 @@ interface = gr.Interface(
|
|
| 80 |
description="Input a paragraph, record your audio, and compare the transcription to the original text."
|
| 81 |
)
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
# Launch Gradio app
|
| 84 |
-
|
|
|
|
| 1 |
import speech_recognition as sr
|
| 2 |
import difflib
|
| 3 |
import gradio as gr
|
| 4 |
+
from gtts import gTTS
|
| 5 |
+
import os
|
| 6 |
|
| 7 |
# Step 1: Transcribe the audio file
|
| 8 |
def transcribe_audio(audio):
|
|
|
|
| 59 |
|
| 60 |
return output
|
| 61 |
|
| 62 |
+
# Step 3: Text-to-Speech Function
|
| 63 |
+
def text_to_speech(paragraph):
|
| 64 |
+
tts = gTTS(paragraph)
|
| 65 |
+
tts.save("paragraph.mp3")
|
| 66 |
+
return "paragraph.mp3"
|
| 67 |
+
|
| 68 |
# Gradio Interface Function
|
| 69 |
def gradio_function(paragraph, audio):
|
| 70 |
# Transcribe the audio
|
|
|
|
| 88 |
description="Input a paragraph, record your audio, and compare the transcription to the original text."
|
| 89 |
)
|
| 90 |
|
| 91 |
+
# Gradio Interface for Text-to-Speech
|
| 92 |
+
tts_interface = gr.Interface(
|
| 93 |
+
fn=text_to_speech,
|
| 94 |
+
inputs=gr.Textbox(lines=5, label="Input Paragraph to Read Aloud"),
|
| 95 |
+
outputs=gr.Audio(label="Text-to-Speech Output", type="filepath"),
|
| 96 |
+
title="Text-to-Speech",
|
| 97 |
+
description="This tool will read your input paragraph aloud."
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
# Combine both interfaces into one
|
| 101 |
+
demo = gr.TabbedInterface([interface, tts_interface], ["Speech Recognition", "Text-to-Speech"])
|
| 102 |
+
|
| 103 |
# Launch Gradio app
|
| 104 |
+
demo.launch()
|