AudioUtils
December 22, 2023 ยท View on GitHub
from tdw.audio_utils import AudioUtils
Utility class for recording audio in TDW using fmedia.
Usage:
from tdw.audio_utils import AudioUtils
from tdw.controller import Controller
c = Controller()
initialize_trial() # Your code here.
# Begin recording audio. Automatically stop recording at 10 seconds.
AudioUtils.start(output_path="path/to/file.wav", until=(0, 10))
do_trial() # Your code here.
# Stop recording.
AudioUtils.stop()
Class Variables
| Variable | Type | Description | Value |
|---|---|---|---|
RECORDER_PROCESS | Optional[Popen] | The current fmedia process. | None |
DEVICE | Optional[int] | The index of the audio capture device. | None |
Functions
get_system_audio_device
AudioUtils.get_system_audio_device()
AudioUtils.get_system_audio_device(device_name=None)
(Static)
| Parameter | Type | Default | Description |
|---|---|---|---|
| device_name | str | None | The name of the audio capture device. If None, defaults to "Stereo Mix" (Windows and Linux) or "iShowU Audio Capture" (OS X). |
Returns: The index audio device that can be used to capture system audio as a string.
start
AudioUtils.start(output_path, until)
AudioUtils.start(output_path, until, device_name=None)
(Static)
Start recording audio.
| Parameter | Type | Default | Description |
|---|---|---|---|
| output_path | PATH | The path to the output file. | |
| until | Optional[Tuple[int, int] | If not None, fmedia will record until minutes:seconds. The value must be a tuple of 2 integers. If None, fmedia will record until you send AudioUtils.stop(). | |
| device_name | str | None | The name of the audio capture device. If None, defaults to "Stereo Mix" (Windows and Linux) or "iShowU Audio Capture" (OS X). |
stop
AudioUtils.stop()
(Static)
Stop recording audio (if any fmedia process is running).
is_recording
AudioUtils.is_recording()
(Static)
Returns: True if the fmedia recording process still exists.