1

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)
3
  • you got any solution for this r.recognize_google(audio) ??? i got the same error too. Commented Feb 11, 2019 at 11:51
  • No not yet. I'll let you know if I find one. Commented Feb 12, 2019 at 17:46
  • any luck yet??? Commented Mar 28, 2019 at 17:10

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0
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()

Comments

0
This code works fine as well

r = sr.Recognizer()    
with sr.Microphone() as source:
    r.energy_threshold = 10000
    r.adjust_for_ambient_noise(source, 1.2)
    print("listening..")    
    audio = r.listen(source)    
    text = r.recognize_google(audio)        
    try:
        print(text)        
    except Exception as e:            
        print("Error" + str(e))

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.