-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect_input_windows.py
More file actions
113 lines (90 loc) · 3.37 KB
/
Copy pathselect_input_windows.py
File metadata and controls
113 lines (90 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python3
"""
Windows Audio Device Selector for Musico
Lists available audio input devices and allows selection
"""
import pyaudio
import sys
def list_audio_devices():
"""List all available audio input devices"""
print("Musico Windows - Audio Device Selector")
print("=" * 40)
try:
audio = pyaudio.PyAudio()
print("\nAvailable audio input devices:")
print("-" * 40)
input_devices = []
for i in range(audio.get_device_count()):
info = audio.get_device_info_by_index(i)
if info['maxInputChannels'] > 0:
input_devices.append((i, info))
print(f" {i}: {info['name']}")
print(f" Channels: {info['maxInputChannels']}")
print(f" Sample Rate: {info['defaultSampleRate']}")
print()
if not input_devices:
print("No input devices found!")
return None
# Try to find a microphone device
microphone_device = None
for device_id, info in input_devices:
if any(keyword in info['name'].lower() for keyword in ['microphone', 'mic', 'audio', 'input']):
microphone_device = device_id
print(f"Auto-selected microphone: {info['name']} (Device {device_id})")
break
if microphone_device is None:
# Use the first available input device
microphone_device = input_devices[0][0]
print(f"Using first available device: {input_devices[0][1]['name']} (Device {microphone_device})")
audio.terminate()
return microphone_device
except Exception as e:
print(f"Error listing audio devices: {e}")
return None
def test_audio_device(device_id):
"""Test recording from a specific audio device"""
print(f"\nTesting audio device {device_id}...")
try:
audio = pyaudio.PyAudio()
# Test recording
stream = audio.open(
format=pyaudio.paInt16,
channels=1,
rate=44100,
input=True,
input_device_index=device_id,
frames_per_buffer=1024
)
print("Recording 2 seconds of audio...")
frames = []
for _ in range(0, int(44100 / 1024 * 2)):
data = stream.read(1024)
frames.append(data)
stream.stop_stream()
stream.close()
audio.terminate()
print("Audio recording test successful!")
return True
except Exception as e:
print(f"Error testing audio device: {e}")
return False
def main():
"""Main function"""
print("Musico Windows Audio Setup")
print("=" * 30)
# List devices
device_id = list_audio_devices()
if device_id is None:
print("No suitable audio device found!")
input("Press Enter to exit...")
return
# Test the device
if test_audio_device(device_id):
print(f"\n✅ Audio device {device_id} is working correctly!")
print("You can now run Musico with: run_windows.bat")
else:
print(f"\n❌ Audio device {device_id} failed the test!")
print("Please check your microphone settings and try again.")
input("\nPress Enter to exit...")
if __name__ == "__main__":
main()