Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any way to use SpeechRecognition with wasapi loopback? #21

Open
5 tasks
ghost opened this issue Aug 11, 2024 · 4 comments
Open
5 tasks

Is there any way to use SpeechRecognition with wasapi loopback? #21

ghost opened this issue Aug 11, 2024 · 4 comments

Comments

@ghost
Copy link

ghost commented Aug 11, 2024

What problem are you facing?

  • audio isn`t recorded
  • audio is recorded with artifacts
  • problem with "silence"
  • [ x] other

What is the cause of the error (in your opinion)?

  • PyAudio\PortAudio bug
  • [ x] I just need help(or answer)

Before creating, complete the checklist:

If the problem is related to the inability to record sound from speakers,
then before creating this issue, try to first record audio using the provided examples
(for example, simple_recording_app.py)

Start your issue here 👇

Is there any way to use SpeechRecognition with wasapi?
like this
`
import pyaudiowpatch as pyaudio
import speech_recognition as sr

p = pyaudio.Pyaudio()
recognizer = sr.Recognizer()

default_speakers = p.get_default_wasapi_loopback()

rate = int(default_speakers["defaultSampleRate"])
channels = default_speakers["maxInputChannels"]
print(f"Recording from: ({default_speakers['index']}) {rate} {channels} {default_speakers['name']}")

stream = p.open(
format=data_format,
channels=channels,
rate=rate,
frames_per_buffer=1024,
input=True,
input_device_index=default_speakers["index"],
)

recognizer.listen_in_background(stream.read(4096)) # i tried but doesnt work

`
any help would be appreciated!

@ghost
Copy link
Author

ghost commented Aug 11, 2024

(in real time)

@s0d3s
Copy link
Owner

s0d3s commented Sep 23, 2024

Hi🖐 Its depends on SpeechRecognition. If it can do STT in real-time, then you can do it. In turn, PyAudio can do what you need, but maybe you will need to increase the frames_per_buffer size, or do manual buffering

@ghost
Copy link
Author

ghost commented Sep 26, 2024

Could you provide me for the code as an example ? Much appreciated!

@s0d3s
Copy link
Owner

s0d3s commented Sep 27, 2024

@imposterfromtheamongus You can use this project as reference:
https://github.com/SevaSk/ecoute/
https://github.com/SevaSk/ecoute/blob/main/AudioRecorder.py

There inside custom version of SpeachRecognition but only reason for it - is to switch from PyAudio to WPatch-version. I think here exists option to use only custom Microphone class(not whole SpeachRecognition), which will be overriden with WPatch. But you have to work it out on your own. Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant