D
D
DmitrNy ---2019-11-22 17:01:22
Python
DmitrNy ---, 2019-11-22 17:01:22

When run, the code gives an error. Python module pyttsx3/spech_recognition (?

When I try to run the code, it throws an error:

File "c:/Users/User/Desktop/Обучение/Проекты Python/ПРОЕКТЫ ЗАДАНИЙ/Всё голосовое/main.py", line 26, in <module>
    audio = r.listen(sourse)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\speech_recognition\__init__.py", line 594, in listen
    assert source.stream is not None, "Audio source must be entered before listening, see documentation for ``AudioSource``; are you using ``source`` outside of a ``with`` statement?"
AssertionError: Audio source must be entered before listening, see documentation for ``AudioSource``; are you using ``source`` outside of a ``with`` statement?

The code:
import os
import time
import speech_recognition as sr
import pyttsx3
from fuzzywuzzy import fuzz
import datetime
engine = pyttsx3.init()  
r = sr.Recognizer()
m =  sr.Microphone(device_index= 1)


with m as sourse:
    r.adjust_for_ambient_noise(sourse)

audio = r.listen(sourse)
. . .

After the ellipsis comes the correct ending code, checked

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-11-23
@sanya84

Maybe so?

with m as sourse:
    r.adjust_for_ambient_noise(sourse)
    audio = r.listen(sourse)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question