Error opening Stream: Invalid number of channels [PaErrorCode -9998]
Getting this error from a L/R switched I'm uploading to github -
File "x\Desktop\Coding\Github Shit\Desktop Audio LR Flipper\scripttest.py", line 33, in
This is the code that came from the error -
import sounddevice as sd import numpy as np import threading import pystray from PIL import Image, ImageDraw
INPUT_ID = 7 # CABLE Input (replace with your actual ID) OUTPUT_ID = 6 # Real Speakers (replace with your actual ID)
def callback(indata, outdata, frames, time, status): if status: print("Status:", status) # Ensure stereo if indata.shape[1] == 2: # Flip L <-> R outdata[:] = indata[:, ::-1] else: # If mono, duplicate channel outdata[:] = np.repeat(indata, 2, axis=1)
def start_stream(): stream = sd.Stream( samplerate=48000, blocksize=1024, dtype="float32", channels=2, device=(INPUT_ID, OUTPUT_ID), # Force specific devices callback=callback ) stream.start() print("Stream running. Ctrl+C to stop.") while True: pass
def stop_stream(): global stream if stream is not None: stream.stop() stream.close() stream = None
def toggle(icon, item): global running running = not running
def quit_app(icon, item): stop_stream() icon.stop()
def make_icon(): img = Image.new("RGB", (64, 64), "black") draw = ImageDraw.Draw(img) draw.polygon([(10, 20), (54, 20), (32, 44)], fill="white") return img
def tray(): icon = pystray.Icon( "Audio Flip", make_icon(), "Audio Flip", menu=pystray.Menu( pystray.MenuItem("Toggle", toggle), pystray.MenuItem("Quit", quit_app) ) ) icon.run()
if name == "main": start_stream() t = threading.Thread(target=tray) t.daemon = True t.start() #this is only here for the github issue, its wrapping it for some reason try: while True: pass except KeyboardInterrupt: stop_stream()
Can you please use Markdown formatting to make your issue more readable?
For a few hints, see https://python-sounddevice.readthedocs.io/en/0.5.3/contributing.html#reporting-problems.