bastibe / SoundCard

A Pure-Python Real-Time Audio Library
https://soundcard.readthedocs.io
BSD 3-Clause "New" or "Revised" License
689 stars 70 forks source link

Something went wrong on Windows #95

Closed Dustin-Jiang closed 3 years ago

Dustin-Jiang commented 4 years ago

When I installed SoundCard and ran the example code on Windows Server via remote desktop, there was an error,

Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import numpy
>>> import soundcard as sc
>>> default_mic = sc.default_microphone()
>>> print(default_mic)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\soundcard\mediafoundation.py", line 462, in __repr__
    return '<Microphone {} ({} channels)>'.format(self.name,self.channels)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\soundcard\mediafoundation.py", line 372, in name
    devicename = ''.join(chr(c) for c in data[0:idx])
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\soundcard\mediafoundation.py", line 372, in <genexpr>
    devicename = ''.join(chr(c) for c in data[0:idx])
ValueError: chr() arg not in range(0x110000)

I don't know what was wrong so could you please tell me how to deal with it? The server environment is

Thanks a lot

bastibe commented 4 years ago

This might be an issue with your soundcard's name. What is the soundcard called on your machine?

ywjung328 commented 3 years ago

Facing the exact solution, with the code below :

import soundcard as sc
import numpy

speakers = sc.all_speakers()
default_speaker = sc.default_speaker()
# mics = sc.all_microphones(include_loopback=True)
mics = sc.all_microphones()
default_mic = sc.default_microphone()

print(speakers)
print(default_speaker)
print(mics)
print(default_mic)

with the error :

Traceback (most recent call last):
  File "c:\arduino_led\audio_led_wasapi.py", line 13, in <module>
    print(speakers)
  File "C:\Users\yeonwoo328\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\soundcard\mediafoundation.py", line 428, in __repr__
    return '<Speaker {} ({} channels)>'.format(self.name,self.channels)
  File "C:\Users\yeonwoo328\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\soundcard\mediafoundation.py", line 372, in name
    devicename = ''.join(chr(c) for c in data[0:idx])
  File "C:\Users\yeonwoo328\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\soundcard\mediafoundation.py", line 372, in <genexpr>
    devicename = ''.join(chr(c) for c in data[0:idx])
ValueError: chr() arg not in range(0x110000)

The same error comes out whatever I try to print between speakers, default_speaker, mics, and default_mic. Is it can be something related to the language I'm using?

ywjung328 commented 3 years ago

self solution :

It was due to language setting. Checked the "data" in mediafoundation.py/ _Device class / name function and overflow was occuring. I temporarily solved it by simply dropping the overflown values, which are under 0 I believe.

image

bastibe commented 3 years ago

Should be fixed in #120. Sorry about that.