Sitelet https://github.com/spatialaudio/python-sounddevice/issues/545
Skip to content

Question on How to Get R and L Mic/StereoMix Volume Data #545

Description

@ns96

Hi,
I am working on a small script which reads data from the Mic/StereoMix devices on Windows and want to be able to get the volume data for the R and L channels separately. I suspect it should be an easy thing to do, but couldn't find any examples searching online. Here is the code I have so far which gets the volume data as a single value, and sends it to the PeppyMeter program over http.

# script to read mic or any input device and send it to PeppyMeter for display
#!/usr/bin/env python3
import numpy as np
import sounddevice as sd
import requests


# specify the input device number in this case stereo mix
input_device = 18
peppy_url = 'http://localhost:8001/vumeter'
#peppy_url = 'http://192.168.1.240:8001/vumeter'

print(sd.query_devices())

print("\nEnter 'q' or 'Q' to Exit")

# function to handle data from audio input device 
def audio_callback(indata, frames, time, status):
    volume_norm = int(np.linalg.norm(indata) * 10)
    #print(volume_norm)
    print("|" * volume_norm)
   
    # send json volume data
    volume_data = {"left": volume_norm, "right": volume_norm, "mono":volume_norm}
    response = requests.put(peppy_url, json=volume_data)
    #print(response)

try:
    stream = sd.InputStream(device=input_device, callback=audio_callback)
    with stream:
        while True:
            response = input()
            if response in ('', 'q', 'Q'):
                break

except KeyboardInterrupt:
    print('Interrupted by user')
except Exception as e:
    print(type(e).__name__ + ': ' + str(e))  

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions