How to use the command `pw-cat` (with examples)
- Linux
- November 5, 2023
This article will illustrate different use cases of the command pw-cat
.
Description
The pw-cat
command is used to play and record audio files through pipewire. It is a command-line tool that allows users to control audio playback and recording using different options such as volume, sample rate, etc. It provides a convenient way to manipulate audio files in various scenarios.
Use case 1: Play a WAV file over the default target
Code:
pw-cat --playback path/to/file.wav
Motivation: This use case is useful when you want to play a WAV file over the default audio target. It allows you to enjoy audio playback without any additional configurations.
Explanation:
--playback
: This option indicates that the command is used for audio playback.path/to/file.wav
: This argument specifies the path to the WAV file that you want to play.
Example Output: The audio file file.wav
will be played over the default target, and you will be able to hear the audio.
Use case 2: Record a sample recording at a different volume level
Code:
pw-cat --record --volume=0.1 path/to/file.wav
Motivation: Sometimes, you may need to adjust the volume level while recording audio to ensure optimal sound quality. This use case allows you to record a sample recording at a lower volume level.
Explanation:
--record
: This option indicates that the command is used for audio recording.--volume=0.1
: This argument sets the volume level to 0.1, where 0 represents silence and 1 represents maximum volume.path/to/file.wav
: This argument specifies the path to the WAV file where the recorded audio will be saved.
Example Output: The command will start recording audio at a volume level of 0.1 and save the recorded audio into the specified WAV file.
Use case 3: Record a sample recording using a different sample rate
Code:
pw-cat --record --rate=6000 path/to/file.wav
Motivation: Changing the sample rate can be useful when you want to record audio with a specific frequency response. This use case allows you to record a sample recording using a sample rate of 6000.
Explanation:
--record
: This option indicates that the command is used for audio recording.--rate=6000
: This argument sets the sample rate to 6000, which determines the number of samples taken per second.path/to/file.wav
: This argument specifies the path to the WAV file where the recorded audio will be saved.
Example Output: The command will start recording audio at a sample rate of 6000 and save the recorded audio into the specified WAV file.
Conclusion:
The pw-cat
command is a versatile tool for playing and recording audio files through pipewire. Its various options allow users to customize audio playback and recording according to their requirements. Whether you want to play a WAV file, adjust the volume level, or change the sample rate, pw-cat
provides a straightforward way to manipulate audio files and achieve desired outcomes.