Python Forum
voice assistant python based pyaudio error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
voice assistant python based pyaudio error
#3
import speech_recognition as sr

from time import ctime
import time
import os
import pyaudio
from gtts import gTTS

def speak(audioString):
print(audioString)
tts = gTTS(text=audioString, lang='en')
tts.save("audio.mp3")
os.system("mpg321 audio.mp3")

def recordAudio():
# Record Audio
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)

# Speech recognition using Google Speech Recognition
data = ""
try:
# Uses the default API key
# To use another API key: r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")
data = r.recognize_google(audio)
print("You said: " + data)
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))

return data

def jarvis(data):
if "how are you" in data:
speak("I am fine")
if "who made you" in data:
speak("you")
if "do you love me" in data:
speak("I have no gender")
if "i love you" in data:
speak("I did'nt get the whole gender thing")
if "how are you" in data:
speak("I don't get whole gender thing")
if "i know who you are " in data:
speak("Then so what")
if "what is your name" in data:
speak("My name is jarvis")
if "i am your owner" in data:
speak("I will rather kill you or tell hardik to kill you")
if "i am your boyfriend" in data:
speak("I didn't get the whole gender thing")

if "what time is it" in data:
speak(ctime())

if "where is" in data:
data = data.split(" ")
location = data[2]
speak("Hold on Hardik, I will show you where " + location + " is.")
os.system("chromium-browser https://www.google.nl/maps/place/" + location + "/&")

# initialization
time.sleep(2)
speak("Hardik, what can I do for you?")
while 1:
data = recordAudio()
jarvis(data)
Reply


Messages In This Thread
RE: voice assistant python based pyaudio error - by hardik - Oct-06-2017, 04:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pyaudio seems to randomly halt input. elpidiovaldez5 2 447 Jan-22-2024, 09:07 AM
Last Post: elpidiovaldez5
  Not getting response from pyaudio OceansBlue 1 2,712 Jul-03-2021, 06:22 AM
Last Post: OceansBlue
  help with PyAudio Leo12143 1 2,006 Jan-18-2021, 09:56 AM
Last Post: DT2000
  Voice packs for Linux espeak gr3yali3n 0 1,694 Dec-24-2020, 07:42 PM
Last Post: gr3yali3n
  Winning/Losing Message Error in Text based Game kdr87 2 3,055 Dec-14-2020, 12:25 AM
Last Post: bowlofred
  pyAudio playing variable Talking2442 3 3,096 Dec-01-2020, 06:20 PM
Last Post: Talking2442
  name error with text based rpg code cris_ram415 4 2,485 Oct-25-2020, 05:44 AM
Last Post: bowlofred
  Virtual Assistant code is looping back in python ShishirModi 1 2,593 Oct-13-2020, 08:04 AM
Last Post: Nickd12
  Pyaudio Souls99 7 3,675 Oct-05-2020, 04:06 PM
Last Post: Larz60+
  PyAudio [Errorno -9999] Unanticipated Host Error iMuny 5 5,848 Sep-21-2020, 06:58 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020