Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,23 +3,21 @@ import pandas as pd
|
|
| 3 |
import time
|
| 4 |
import gtts
|
| 5 |
import os
|
| 6 |
-
import
|
|
|
|
| 7 |
import speech_recognition as sr
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
pygame.mixer.init()
|
| 11 |
|
| 12 |
# Function to convert text to speech
|
| 13 |
def speak_text(text):
|
| 14 |
tts = gtts.gTTS(text)
|
| 15 |
-
|
| 16 |
-
tts.save(
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
pygame.mixer.music.unload()
|
| 22 |
-
os.remove(filename)
|
| 23 |
|
| 24 |
# Function to recognize speech input
|
| 25 |
def recognize_speech():
|
|
|
|
| 3 |
import time
|
| 4 |
import gtts
|
| 5 |
import os
|
| 6 |
+
import sounddevice as sd
|
| 7 |
+
import numpy as np
|
| 8 |
import speech_recognition as sr
|
| 9 |
+
import tempfile
|
| 10 |
+
import scipy.io.wavfile as wav
|
|
|
|
| 11 |
|
| 12 |
# Function to convert text to speech
|
| 13 |
def speak_text(text):
|
| 14 |
tts = gtts.gTTS(text)
|
| 15 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
|
| 16 |
+
tts.save(temp_file.name)
|
| 17 |
+
data, samplerate = wav.read(temp_file.name)
|
| 18 |
+
sd.play(data, samplerate)
|
| 19 |
+
sd.wait()
|
| 20 |
+
os.remove(temp_file.name)
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# Function to recognize speech input
|
| 23 |
def recognize_speech():
|