Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,14 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from responser import responsr
|
3 |
-
from gtts import gTTS
|
4 |
-
from io import BytesIO
|
5 |
-
|
6 |
import streamlit as st
|
7 |
from responser import responsr
|
8 |
from gtts import gTTS
|
9 |
from io import BytesIO
|
10 |
import whisper
|
11 |
-
import
|
12 |
import numpy as np
|
13 |
-
import time
|
14 |
|
15 |
# Load Whisper model
|
16 |
whisper_model = whisper.load_model("base")
|
17 |
|
18 |
-
# Initialize PyAudio
|
19 |
-
p = pyaudio.PyAudio()
|
20 |
-
|
21 |
# Function to convert text to speech and return audio file
|
22 |
def text_to_speech(text):
|
23 |
tts = gTTS(text)
|
@@ -28,15 +19,11 @@ def text_to_speech(text):
|
|
28 |
|
29 |
# Function to record audio from the microphone
|
30 |
def record_audio(duration=5, fs=16000):
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
stream.stop_stream()
|
37 |
-
stream.close()
|
38 |
-
audio_data = b''.join(frames)
|
39 |
-
return np.frombuffer(audio_data, dtype=np.int16)
|
40 |
|
41 |
# Function to recognize speech using Whisper
|
42 |
def recognize_speech(audio_data):
|
@@ -69,7 +56,6 @@ def main():
|
|
69 |
|
70 |
# Button to record audio input
|
71 |
if st.button('Record Audio'):
|
72 |
-
st.write("Recording...")
|
73 |
audio_data = record_audio(duration=5) # Adjust duration as needed
|
74 |
st.write("Processing...")
|
75 |
user_input = recognize_speech(audio_data)
|
@@ -107,6 +93,3 @@ def main():
|
|
107 |
|
108 |
if __name__ == "__main__":
|
109 |
main()
|
110 |
-
|
111 |
-
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from responser import responsr
|
3 |
from gtts import gTTS
|
4 |
from io import BytesIO
|
5 |
import whisper
|
6 |
+
import sounddevice as sd
|
7 |
import numpy as np
|
|
|
8 |
|
9 |
# Load Whisper model
|
10 |
whisper_model = whisper.load_model("base")
|
11 |
|
|
|
|
|
|
|
12 |
# Function to convert text to speech and return audio file
|
13 |
def text_to_speech(text):
|
14 |
tts = gTTS(text)
|
|
|
19 |
|
20 |
# Function to record audio from the microphone
|
21 |
def record_audio(duration=5, fs=16000):
|
22 |
+
st.write("Recording...")
|
23 |
+
audio_data = sd.rec(int(duration * fs), samplerate=fs, channels=1, dtype='int16')
|
24 |
+
sd.wait() # Wait until recording is finished
|
25 |
+
st.write("Recording complete.")
|
26 |
+
return audio_data.flatten()
|
|
|
|
|
|
|
|
|
27 |
|
28 |
# Function to recognize speech using Whisper
|
29 |
def recognize_speech(audio_data):
|
|
|
56 |
|
57 |
# Button to record audio input
|
58 |
if st.button('Record Audio'):
|
|
|
59 |
audio_data = record_audio(duration=5) # Adjust duration as needed
|
60 |
st.write("Processing...")
|
61 |
user_input = recognize_speech(audio_data)
|
|
|
93 |
|
94 |
if __name__ == "__main__":
|
95 |
main()
|
|
|
|
|
|