Python Forum
Capture Sound from Mirophone and speakers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Capture Sound from Mirophone and speakers
#1
We are using amazon transcribe to make speach to text but we need to capture sound from both microphone and speakers. Do you think that this can be done with sounddevice or should we use something else?

https://github.com/awslabs/amazon-transcribe-streaming-sdk/blob/develop/examples/simple_mic.py]amazon-transcribe-streaming-sdk

In Mic Function i also let in comments some tests i done:

async def mic_stream():
    # This function wraps the raw input stream from the microphone forwarding
    # the blocks to an asyncio.Queue.
    loop = asyncio.get_event_loop()
    input_queue = asyncio.Queue()

    def callback(indata, outdata, frame_count, time_info, status):
        '''
        if status:
            print(status)
        '''
        #indata[:] = outdata
        loop.call_soon_threadsafe(input_queue.put_nowait, (bytes(indata), status))

    # Be sure to use the correct parameters for the audio stream that matches
    # the audio formats described for the source language you'll be using:
    # https://docs.aws.amazon.com/transcribe/latest/dg/streaming.html
    stream = sounddevice.RawStream(
        #device=3,
        channels=1,
        samplerate=16000,
        callback=callback,
        blocksize=1024 * 2,
        dtype="int16",
    )
    # Initiate the audio stream and asynchronously yield the audio chunks
    # as they become available.
    with stream:
        while True:
            indata, status = await input_queue.get()
            yield indata, status
Reply
#2
hello guys

We have tested the script with varius devices. With Corsair HS45 Surround USB Sound Adapter i was able to capture sound from both microphone and speakers, but with HP X1000 Wireless Gaming Headsetwe are unable to get any data from speakers. Here is the script:

async def mic_stream():
    # This function wraps the raw input stream from the microphone forwarding
    # the blocks to an asyncio.Queue.
    loop = asyncio.get_event_loop()
    input_queue = asyncio.Queue()

    def callback(indata, frame_count, time_info, status):
        loop.call_soon_threadsafe(input_queue.put_nowait, (bytes(indata), status))

    stream = sounddevice.RawInputStream(
        #device=[1,25],
        channels=1,
        samplerate=16000,
        callback=callback,
        blocksize=1024 * 2,
        dtype="int16",
    )
    # Initiate the audio stream and asynchronously yield the audio chunks
    # as they become available.
    with stream:
        while True:
            indata, status = await input_queue.get()
            yield indata, status
and here are the settings from the devices:
Corsair HS45 Surround USB Sound Adapter
   0 Microsoft Sound Mapper - Input, MME (2 in, 0 out)
>  1 Headset Microphone (Corsair HS4, MME (2 in, 0 out)
   2 FrontMic (Realtek High Definiti, MME (2 in, 0 out)
   3 Microsoft Sound Mapper - Output, MME (0 in, 2 out)
<  4 Headset Earphone (Corsair HS45 , MME (0 in, 2 out)
   5 Realtek Digital Output (Realtek, MME (0 in, 2 out)
   6 Speakers (Realtek High Definiti, MME (0 in, 2 out)
2- HP X1000 Wireless Gaming Headset (Sound Research)
   0 Microsoft Sound Mapper - Input, MME (2 in, 0 out)
>  1 Headset Microphone (2- HP X1000, MME (2 in, 0 out)
   2 FrontMic (Realtek High Definiti, MME (2 in, 0 out)
   3 Microsoft Sound Mapper - Output, MME (0 in, 2 out)
<  4 Headset Earphone (2- HP X1000 W, MME (0 in, 2 out)
   5 Realtek Digital Output (Realtek, MME (0 in, 2 out)
   6 Speakers (Realtek High Definiti, MME (0 in, 2 out)   
Can anyone help?
Reply
#3
Hello,
what parameters have you defined in input to sounddevice.RawInputStream to get the sounds from both microphone and output speakerCorsair HS45? and on what Operating System you run?

Bye
Reply
#4
(Sep-12-2021, 01:30 PM)dioniso1981 Wrote: Hello,
what parameters have you defined in input to sounddevice.RawInputStream to get the sounds from both microphone and output speakerCorsair HS45? and on what Operating System you run?

Bye
Im testing it on windows 10 and debian Buster but on windows I found out that the sidetone was enable on corsair and that was probably the reason that it was working. When i try to use HP X1000 i was unable to capture the sound from headset but only from microphone. so i increase the samplerate to 48k and i was able to get sound from headset but not from microphone. any idea how to combine then and make them working at the same time?

stream = sounddevice.RawInputStream(
        channels=1,
        samplerate=16000,
        callback=callback,
        blocksize=1024 * 2,
        dtype="int16",
    )
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020