How to use the command pactl (with examples)

How to use the command pactl (with examples)

Pactl is a command-line tool used to control a running PulseAudio sound server. It allows users to manage audio sinks, change default audio outputs, adjust volumes, and toggle mute. This article provides examples of various use cases of the pactl command.

Use case 1: List all sinks

Code:

pactl list sinks short

Motivation: This use case is helpful if you want to see a list of available audio outputs (sinks) on your system.

Explanation: The list subcommand fetches information about different audio components. By specifying list sinks, it retrieves a list of all available sinks, including their index, name, and description.

Example output:

0	alsa_output.pci-0000_00_1f.3.analog-stereo	module-alsa-card.c	s16le 2ch 44100Hz	SUSPENDED
1	bluez_sink.00_12_3F_61_37_DA.a2dp_sink	module-bluez5-device.c	s16le 2ch 44100Hz	IDLE

Use case 2: Change the default sink

Code:

pactl set-default-sink 1

Motivation: If you have multiple audio outputs and want to set a different one as the default sink, this use case comes in handy.

Explanation: The set-default-sink command allows you to change the default audio output (sink) by specifying the sink index as an argument. In this example, 1 represents the index of the desired sink.

Example output: No output is displayed if the command executes successfully.

Use case 3: Move sink-input to a different sink

Code:

pactl move-sink-input 627 1

Motivation: If you want to redirect audio from a specific source to a different audio output, this use case is useful. For example, you may want to play music on external speakers instead of the default sink.

Explanation: The move-sink-input command moves a sink input (audio stream) from its current sink to a different sink. In this example, 627 represents the sink-input index, and 1 represents the index of the sink to which the input should be moved.

Example output: No output is displayed if the command executes successfully.

Use case 4: Set the volume of a sink

Code:

pactl set-sink-volume 1 0.75

Motivation: This use case allows you to adjust the volume level of a specific audio output (sink). It can be helpful when you want to control individual output volumes.

Explanation: The set-sink-volume command sets the volume of a sink by specifying the sink index followed by the volume level. In this example, 1 represents the index of the sink, and 0.75 represents the desired volume level (75%).

Example output: No output is displayed if the command executes successfully.

Use case 5: Toggle mute on the default sink

Code:

pactl set-sink-mute @DEFAULT_SINK@ toggle

Motivation: If you need to quickly mute or unmute the default audio output, this use case provides a convenient way to toggle the mute status.

Explanation: The set-sink-mute command allows you to toggle the mute status of a sink by specifying the sink using its special name @DEFAULT_SINK@. The toggle argument instructs the command to switch the mute status between on and off.

Example output: No output is displayed if the command executes successfully.

Conclusion:

The pactl command is a versatile tool for managing audio outputs and controlling audio-related settings on a PulseAudio sound server. The various use cases discussed in this article provide examples of how to list sinks, change the default sink, move sink-inputs, adjust sink volumes, and toggle mute. Understanding and utilizing these commands can enhance the audio management experience on a Linux system.

Related Posts

How to use the command aireplay-ng (with examples)

How to use the command aireplay-ng (with examples)

In wireless network security testing, it often becomes necessary to inject packets into a network to perform various attacks.

Read More
How to use the command phploc (with examples)

How to use the command phploc (with examples)

PHPLOC is a command-line tool that analyzes the size and structure of a PHP project.

Read More
How to use the command ajson (with examples)

How to use the command ajson (with examples)

The command ajson is a tool that allows you to execute JSONPath expressions on JSON objects.

Read More