Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import whisper
|
3 |
from gtts import gTTS
|
@@ -9,7 +10,7 @@ import os
|
|
9 |
from pydub import AudioSegment
|
10 |
|
11 |
# Load the Whisper model
|
12 |
-
whisper_model = whisper.load_model("
|
13 |
|
14 |
# Define transcription function
|
15 |
def transcribe_and_generate_response(audio_input):
|
@@ -17,26 +18,20 @@ def transcribe_and_generate_response(audio_input):
|
|
17 |
if audio_input is None:
|
18 |
return "No audio input detected.", None
|
19 |
|
20 |
-
# Convert audio to WAV using pydub
|
21 |
audio = AudioSegment.from_file(audio_input)
|
22 |
temp_audio_path = tempfile.NamedTemporaryFile(suffix=".wav", delete=False).name
|
23 |
audio.export(temp_audio_path, format="wav")
|
24 |
|
25 |
-
# Load the audio file using soundfile
|
26 |
-
audio_data, samplerate = sf.read(temp_audio_path)
|
27 |
-
|
28 |
-
# Convert audio_data to float32
|
29 |
-
audio_data = audio_data.astype(np.float32)
|
30 |
-
|
31 |
# Whisper transcribe
|
32 |
-
result = whisper_model.transcribe(
|
33 |
transcription = result.get('text')
|
34 |
|
35 |
if transcription is None:
|
36 |
return "Transcription failed.", None
|
37 |
|
38 |
-
# Get
|
39 |
-
chatbot_response =
|
40 |
|
41 |
# Text-to-speech with gTTS
|
42 |
response_audio = io.BytesIO()
|
@@ -64,3 +59,4 @@ with gr.Blocks() as demo:
|
|
64 |
submit_btn.click(transcribe_and_generate_response, inputs=audio_input, outputs=[transcription_output, chatbot_response_audio])
|
65 |
|
66 |
demo.launch()
|
|
|
|
1 |
+
!pip install pydub
|
2 |
import gradio as gr
|
3 |
import whisper
|
4 |
from gtts import gTTS
|
|
|
10 |
from pydub import AudioSegment
|
11 |
|
12 |
# Load the Whisper model
|
13 |
+
whisper_model = whisper.load_model("medium")
|
14 |
|
15 |
# Define transcription function
|
16 |
def transcribe_and_generate_response(audio_input):
|
|
|
18 |
if audio_input is None:
|
19 |
return "No audio input detected.", None
|
20 |
|
21 |
+
# Convert audio to WAV using pydub
|
22 |
audio = AudioSegment.from_file(audio_input)
|
23 |
temp_audio_path = tempfile.NamedTemporaryFile(suffix=".wav", delete=False).name
|
24 |
audio.export(temp_audio_path, format="wav")
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
# Whisper transcribe
|
27 |
+
result = whisper_model.transcribe(temp_audio_path, language="ur")
|
28 |
transcription = result.get('text')
|
29 |
|
30 |
if transcription is None:
|
31 |
return "Transcription failed.", None
|
32 |
|
33 |
+
# Get a reply from a chatbot model here (replace with your chatbot logic)
|
34 |
+
chatbot_response = f"Your input was: {transcription}" # Replace with actual chatbot response logic
|
35 |
|
36 |
# Text-to-speech with gTTS
|
37 |
response_audio = io.BytesIO()
|
|
|
59 |
submit_btn.click(transcribe_and_generate_response, inputs=audio_input, outputs=[transcription_output, chatbot_response_audio])
|
60 |
|
61 |
demo.launch()
|
62 |
+
|