Commit ·
f1e2b67
1
Parent(s): 142ad0a
Open the audio input with the device's channel count (fixes mono microphones) (#4)
Browse files- Open the audio input with the device's channel count (fixes mono microphones) (1d81003ef3abe7ea9263f5e2b969f769d70baf1a)
Co-authored-by: Austin B <alphatangobravo@users.noreply.huggingface.co>
- spotify_dancer/main.py +9 -1
spotify_dancer/main.py
CHANGED
|
@@ -197,9 +197,17 @@ class AudioAnalyzer:
|
|
| 197 |
self.is_running = True
|
| 198 |
|
| 199 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
self.stream = sd.InputStream(
|
| 201 |
device=self.device_index,
|
| 202 |
-
channels=
|
| 203 |
samplerate=self.sample_rate,
|
| 204 |
blocksize=self.chunk_size,
|
| 205 |
callback=self._audio_callback,
|
|
|
|
| 197 |
self.is_running = True
|
| 198 |
|
| 199 |
try:
|
| 200 |
+
# A plain microphone (e.g. a laptop's built-in one) is mono and PortAudio
|
| 201 |
+
# rejects channels=2 outright; the callback already averages whatever arrives.
|
| 202 |
+
channels = 2
|
| 203 |
+
try:
|
| 204 |
+
info = sd.query_devices(self.device_index)
|
| 205 |
+
channels = max(1, min(2, int(info["max_input_channels"])))
|
| 206 |
+
except Exception:
|
| 207 |
+
pass
|
| 208 |
self.stream = sd.InputStream(
|
| 209 |
device=self.device_index,
|
| 210 |
+
channels=channels,
|
| 211 |
samplerate=self.sample_rate,
|
| 212 |
blocksize=self.chunk_size,
|
| 213 |
callback=self._audio_callback,
|