Audio Recorder Using Python

Опубликовано: 13 Май 2026
на канале: CodeCraft
87
3

In this video, you'll learn how to record audio using Python with the `sounddevice` library and save it as a WAV file using `scipy`. Recording audio in Python can be useful for various applications such as speech recognition, audio processing, and voice-controlled systems.

Here's what we cover in this tutorial:

1. Importing necessary libraries: We import `sounddevice` for recording audio and `scipy.io.wavfile.write` for writing the audio data to a WAV file.

2. Setting the sample rate: We define the sample rate (`fs`) as 44100 samples per second, which is a common rate used in audio recording.

3. Prompting user input: We ask the user to input the duration of the audio recording in seconds.

4. Recording audio: Using the `sounddevice.rec()` function, we record audio for the specified duration at the specified sample rate and number of channels (stereo).

5. Waiting for recording to finish: We use `sounddevice.wait()` to ensure that the recording is completed before proceeding.

6. Writing audio to a WAV file: We use the `write()` function from `scipy.io.wavfile` to save the recorded audio data to a WAV file named "out.wav".

7. Completion message: Finally, we print a message indicating that the recording process is finished and instruct the user to check the output WAV file.

By following this tutorial, you'll be able to easily record audio in Python and integrate it into your projects. Whether you're creating a voice-controlled application or experimenting with audio processing, this tutorial will help you get started. Happy coding!