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

Transcribe from sound card #10

Open
shoegazerstella opened this issue Mar 31, 2023 · 6 comments
Open

Transcribe from sound card #10

shoegazerstella opened this issue Mar 31, 2023 · 6 comments

Comments

@shoegazerstella
Copy link

Hi all,
Thank you for this implementation.
I would like to transcribe from the soundcard, so I would need to specify here a different source.

This is the list of my mic devices:

Microphone with name "MacBook Pro Microphone" found for `Microphone(device_index=1)`
Microphone with name "MacBook Pro Speakers" found for `Microphone(device_index=2)`

So I am adding:

source = sr.Microphone(sample_rate=16000, device_index=2)

but I get the following error:

Traceback (most recent call last):
  File "transcribe_demo_soundcard.py", line 79, in main
    recorder.adjust_for_ambient_noise(source)
  File "/opt/anaconda3/envs/py38/lib/python3.8/site-packages/speech_recognition/__init__.py", line 383, in adjust_for_ambient_noise
    assert source.stream is not None, "Audio source must be entered before adjusting, see documentation for ``AudioSource``; are you using ``source`` outside of a ``with`` statement?"
AssertionError: Audio source must be entered before adjusting, see documentation for ``AudioSource``; are you using ``source`` outside of a ``with`` statement?

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "transcribe_demo_soundcard.py", line 155, in <module>
    main()
  File "transcribe_demo_soundcard.py", line 79, in main
    recorder.adjust_for_ambient_noise(source)
  File "/opt/anaconda3/envs/py38/lib/python3.8/site-packages/speech_recognition/__init__.py", line 189, in __exit__
    self.stream.close()
AttributeError: 'NoneType' object has no attribute 'close'

Any clue why?
Thanks!

@davabase
Copy link
Owner

Looking at the error, the with statement is failing because source is None. Either the line where you set the source was never executed or sr.Microphone() returned None because of an error.

@davabase
Copy link
Owner

Your sound card probably doesn't support being used as a microphone directly. Sometimes Windows will show speakers along with microphones, but the speakers can't be used for recording. You can try using Stereo Mix or a third part virtual cable like vb-audio. See this post also: davabase/transcriber_app#11

@NicoLiendro14
Copy link

Hello everyone, I developed a solution so that I can take the microphone or audio from the system using a modified version of PyAudio. I understand that on Mac it could be different, I could help you by modifying this lib and demo.

@martinshkreli
Copy link

so do it lol

@g-l-i-t-c-h-o-r-s-e
Copy link

Hello everyone, I developed a solution so that I can take the microphone or audio from the system using a modified version of PyAudio. I understand that on Mac it could be different, I could help you by modifying this lib and demo.

pls post it

@wprudencio
Copy link

I'm recording direct from the sound card in Mac Os. I'm using https://github.com/ExistentialAudio/BlackHole

After setting this up, use the code below to list all sound devices.

import pyaudio
audio = pyaudio.PyAudio()
device_count = audio.get_device_count()
for i in range(device_count):
    device_info = audio.get_device_info_by_index(i)
    print(f"Device {i}: {device_info['name']}")
audio.terminate()

The output will be like that.

Device 0: BlackHole 2ch
Device 1: External Microphone
Device 2: External Headphones
Device 3: MacBook Pro Microphone
Device 4: MacBook Pro Speakers
Device 5: Multi-Output Device

Search for sr.Microphone line and add the BlackHole device_index

Screenshot 2023-07-04 at 13 24 05

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

6 participants