1
votes

I'm trying to make a virtual assistant, right now it's suppost to just write down what I say. However when I try to test it it returns,

Traceback (most recent call last): File "/Users/danieldossantos/Desktop/jarvis/chats/main.py", line 14, in speech = r.recognize_google(audio, language = 'pt') File "/Library/Python/2.7/site-packages/speech_recognition/init.py", line 858, in recognize_google if not isinstance(actual_result, dict) or len(actual_result.get("alternative", [])) == 0: raise UnknownValueError() speech_recognition.UnknownValueError

I've checked my code and I haven't found any errors, at least not that I know of,

import speech_recognition as sr

r = sr.Recognizer()

with sr.Microphone() as s:
    r.adjust_for_ambient_noise(s)

    while True:
        audio = r.listen(s)

        speech = r.recognize_google(audio, language = 'pt')

        print('VocĂȘ disse: ', speech)
2
you got any solution for this r.recognize_google(audio) ??? i got the same error too. - Ujwala Patil
No not yet. I'll let you know if I find one. - Daniel dos Santos
any luck yet??? - GigaByte

2 Answers

1
votes

yes, for me now its working. The problem was with audio ports, as most of our laptop have 2 ports :

1. audio out (Green colour)

2. microphone (pink colour)

  • You need to put your headphone jack in Audio out so that it can accept your speech as input.

  • As Your code is unable to get any input it returns error saying empty list []

get("alternative", [])) == 0.

0
votes
import speech_recognition as sr
from os import walk

r = sr.Recognizer()
#optional
#r.energy_threshold = 300

def startConvertion(path = 'file.wav', lang = 'en-IN'): 
    with sr.AudioFile(path) as source:
        #print('Fetching File')
        audio_file = r.record(source)
        print(r.recognize_google(audio_file, language=lang))
startConvertion()