I'm programming a personal assistant with python on windows, it works so bad, some times I have the error 13 - permission denied to the file where the voice is stored. Another times it directly doesn't recognize my voice and other times it expend one minute or more for recognizing my voice. Looking at the code, what things I should improve to make it works better ?
import os
import time
import playsound
import speech_recognition as sr
from gtts import gTTS
def speak(text):
tts = gTTS(text=text, lang="es-ES")
filename = "voice.mp3"
tts.save(filename)
playsound.playsound(filename)
def get_audio():
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
said = ""
try:
said = r.recognize_google(audio, language="es-ES")
print(said)
except Exception as e:
print("Exception: " + str(e))
return said
speak("Di algo")
get_audio()