ScrapExplorer - record.py

Home / misc / plxkit Lines: 2 | Size: 1089 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1import sounddevice as sd 2import soundfile as sf 3 4def record_audio(input_device, filename="output.wav", sample_rate=44100, channels=2, duration=None): 5 """Record audio from input_device into a WAV file. 6 7 Args: 8 input_device (int): device index 9 filename (str): output filename 10 sample_rate (int): sample rate 11 channels (int): number of channels 12 duration (float | None): seconds to record (None = until Enter) 13 """ 14 with sf.SoundFile(filename, mode='w', samplerate=sample_rate, 15 channels=channels) as file: 16 def audio_callback(indata, frames, time, status): 17 if status: 18 print(status) 19 file.write(indata) 20 21 with sd.InputStream(device=input_device, 22 samplerate=sample_rate, 23 channels=channels, 24 callback=audio_callback): 25 if duration: 26 sd.sleep(int(duration * 1000)) 27 else: 28 input(f"Recording to {filename}... press Enter to stop\n") 29
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.