|
1 | 1 | import torch |
2 | 2 | import torchaudio |
3 | 3 | import numpy as np |
4 | | -import sounddevice as sd |
5 | 4 | import tempfile |
6 | 5 | import os |
7 | 6 | import threading |
8 | 7 | import time |
9 | 8 | import queue |
10 | 9 |
|
| 10 | +# Graceful handling of sounddevice/PortAudio dependency |
| 11 | +try: |
| 12 | + import sounddevice as sd |
| 13 | + SOUNDDEVICE_AVAILABLE = True |
| 14 | +except ImportError as e: |
| 15 | + SOUNDDEVICE_AVAILABLE = False |
| 16 | + SOUNDDEVICE_ERROR = str(e) |
| 17 | + print(f"⚠️ ChatterBox Voice Capture: sounddevice not available - {e}") |
| 18 | + print("📋 To enable voice recording, install PortAudio:") |
| 19 | + print(" Linux: sudo apt-get install portaudio19-dev") |
| 20 | + print(" macOS: brew install portaudio") |
| 21 | + print(" Windows: Usually bundled with sounddevice") |
| 22 | + |
11 | 23 | class ChatterBoxVoiceCapture: |
12 | 24 | @classmethod |
13 | 25 | def NAME(cls): |
| 26 | + if not SOUNDDEVICE_AVAILABLE: |
| 27 | + return "🎙️ ChatterBox Voice Capture (diogod) - PortAudio Required" |
14 | 28 | return "🎙️ ChatterBox Voice Capture (diogod)" |
15 | 29 |
|
16 | 30 | @classmethod |
17 | 31 | def INPUT_TYPES(cls): |
| 32 | + if not SOUNDDEVICE_AVAILABLE: |
| 33 | + return { |
| 34 | + "required": { |
| 35 | + "error_message": (["PortAudio library not found. Install with: sudo apt-get install portaudio19-dev (Linux) or brew install portaudio (macOS)"], {"default": "PortAudio library not found. Install with: sudo apt-get install portaudio19-dev (Linux) or brew install portaudio (macOS)"}), |
| 36 | + } |
| 37 | + } |
| 38 | + |
18 | 39 | # Get available audio devices |
19 | 40 | devices = sd.query_devices() |
20 | 41 | device_names = [] |
@@ -80,9 +101,25 @@ def INPUT_TYPES(cls): |
80 | 101 | FUNCTION = "capture_voice_audio" |
81 | 102 | CATEGORY = "ChatterBox Voice" |
82 | 103 |
|
83 | | - def capture_voice_audio(self, voice_device, voice_sample_rate, voice_max_recording_time, |
84 | | - voice_volume_gain, voice_silence_threshold, voice_silence_duration, |
85 | | - voice_auto_normalize, voice_trigger=0): |
| 104 | + def capture_voice_audio(self, **kwargs): |
| 105 | + if not SOUNDDEVICE_AVAILABLE: |
| 106 | + print(f"❌ ChatterBox Voice Capture error: {SOUNDDEVICE_ERROR}") |
| 107 | + print("📋 Install PortAudio to enable voice recording:") |
| 108 | + print(" Linux: sudo apt-get install portaudio19-dev") |
| 109 | + print(" macOS: brew install portaudio") |
| 110 | + print(" Windows: Usually bundled with sounddevice") |
| 111 | + # Return empty audio tensor |
| 112 | + return (torch.zeros(1, 1, 22050),) |
| 113 | + |
| 114 | + # Extract parameters with defaults for graceful fallback |
| 115 | + voice_device = kwargs.get('voice_device', '') |
| 116 | + voice_sample_rate = kwargs.get('voice_sample_rate', 44100) |
| 117 | + voice_max_recording_time = kwargs.get('voice_max_recording_time', 10.0) |
| 118 | + voice_volume_gain = kwargs.get('voice_volume_gain', 1.0) |
| 119 | + voice_silence_threshold = kwargs.get('voice_silence_threshold', 0.02) |
| 120 | + voice_silence_duration = kwargs.get('voice_silence_duration', 2.0) |
| 121 | + voice_auto_normalize = kwargs.get('voice_auto_normalize', True) |
| 122 | + voice_trigger = kwargs.get('voice_trigger', 0) |
86 | 123 |
|
87 | 124 | print(f"🎤 Starting ChatterBox Voice Capture...") |
88 | 125 | print(f"Settings: max_time={voice_max_recording_time}s, volume_gain={voice_volume_gain}x, silence_threshold={voice_silence_threshold}, silence_duration={voice_silence_duration}s, rate={voice_sample_rate}") |
|
0 commit comments