Daniel dos Santos
Daniel dos Santos

Reputation: 271

Python speech_recognition.UnknownValueError

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)

Upvotes: 1

Views: 3759

Answers (3)

Akansha Sharma
Akansha Sharma

Reputation: 1

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

Upvotes: 0

marcin2x4
marcin2x4

Reputation: 1429

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

Upvotes: 0

Ujwala Patil
Ujwala Patil

Reputation: 190

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.

Upvotes: 1

Related Questions