Command to play sound through speakers when headphones on ?

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
User avatar
bartszu
Level 4
Level 4
Posts: 361
Joined: Thu Aug 28, 2014 7:39 pm
Location: Eire

Command to play sound through speakers when headphones on ?

Post by bartszu »

Command to play sound through speakers when headphones on ?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Command to play sound through speakers when headphones on ?

Post by rene »

Likely impossible, with output paths switched in hardware when inserting a headphone.
User avatar
Flemur
Level 20
Level 20
Posts: 10096
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: Command to play sound through speakers when headphones on ?

Post by Flemur »

bartszu wrote: Mon Mar 25, 2019 1:00 amCommand to play sound through speakers when headphones on ?
I get it set up with qasmixer (not installed by default): Set "Auto-Mute Mode" (on lower-left of GUI, *if* it's present) to "Disabled".
qasmixer.jpg
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
User avatar
bartszu
Level 4
Level 4
Posts: 361
Joined: Thu Aug 28, 2014 7:39 pm
Location: Eire

Re: Command to play sound through speakers when headphones on ?

Post by bartszu »

Must be possible Mixx can do it. So there must be command for that.
User avatar
bartszu
Level 4
Level 4
Posts: 361
Joined: Thu Aug 28, 2014 7:39 pm
Location: Eire

Re: Command to play sound through speakers when headphones on ?

Post by bartszu »

Ok lets make it simpler :)
Alarm Clock for LM able to play sound thru speakers while headphones on ???
Very simple feature every clock on Android has.
User avatar
MrEen
Level 23
Level 23
Posts: 18343
Joined: Mon Jun 12, 2017 8:39 pm

Re: Command to play sound through speakers when headphones on ?

Post by MrEen »

It's probably something like pacmd set-sink-port 1 analog-output-lineout or pacmd set-sink-port 1 analog-output-speakers depending what you mean by speakers. Are they built-in, or connected to the Line out port? The number 1 is for the card number involved. Yours may be 0 or higher than 1. The output of aplay -l will give you your card numbers.
User avatar
MrEen
Level 23
Level 23
Posts: 18343
Joined: Mon Jun 12, 2017 8:39 pm

Re: Command to play sound through speakers when headphones on ?

Post by MrEen »

Oh, you want to just play a sound to the port. Give me a few minutes and I might find something.
User avatar
bartszu
Level 4
Level 4
Posts: 361
Joined: Thu Aug 28, 2014 7:39 pm
Location: Eire

Re: Command to play sound through speakers when headphones on ?

Post by bartszu »

Yes I want bloody aplay to play sound to port.
How to make aplay or anything to do that ???
User avatar
bartszu
Level 4
Level 4
Posts: 361
Joined: Thu Aug 28, 2014 7:39 pm
Location: Eire

Re: Command to play sound through speakers when headphones on ?

Post by bartszu »

aplay -l gives me some random drop.
I have one card only one sound card.
Now if I have Bluetooth or headphones on I don't want my alarm to be played on them.
User avatar
MrEen
Level 23
Level 23
Posts: 18343
Joined: Mon Jun 12, 2017 8:39 pm

Re: Command to play sound through speakers when headphones on ?

Post by MrEen »

bartszu wrote: Mon Mar 25, 2019 8:31 pm aplay -l gives me some random drop.
I have one card only one sound card.
Now if I have Bluetooth or headphones on I don't want my alarm to be played on them.
It's a little too involved for me to figure out at this time, but it is something I'm interested in trying to figure out. I'll let you know if I come up with anything.

It may be too much work for me to find and understand so I can't make any guarantees.
User avatar
bartszu
Level 4
Level 4
Posts: 361
Joined: Thu Aug 28, 2014 7:39 pm
Location: Eire

Re: Command to play sound through speakers when headphones on ?

Post by bartszu »

I am going thru your web site, you know tons more about that then me.
This is annoying Linux still needs tons of development.
Don't tell me there is no Alarm Clock for Linux capable of doing that ???

You see problem atm is that I use headphones now but my active port is still: active port: <analog-output-speaker>

Code: Select all

barts@Mint ~ $ pacmd list-sinks
1 sink(s) available.
  * index: 0
	name: <alsa_output.pci-0000_00_08.0.analog-stereo>
	driver: <module-alsa-card.c>
	flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
	state: RUNNING
	suspend cause: 
	priority: 9959
	volume: front-left: 29491 /  45% / -20.81 dB,   front-right: 29491 /  45% / -20.81 dB
	        balance 0.00
	base volume: 65536 / 100% / 0.00 dB
	volume steps: 65537
	muted: no
	current latency: 21.61 ms
	max request: 4 KiB
	max rewind: 64 KiB
	monitor source: 0
	sample spec: s16le 2ch 44100Hz
	channel map: front-left,front-right
	             Stereo
	used by: 5
	linked by: 5
	configured latency: 26.00 ms; range is 26.00 .. 371.52 ms
	card: 0 <alsa_card.pci-0000_00_08.0>
	module: 6
	properties:
		alsa.resolution_bits = "16"
		device.api = "alsa"
		device.class = "sound"
		alsa.class = "generic"
		alsa.subclass = "generic-mix"
		alsa.name = "92HD73C1X5 Analog"
		alsa.id = "92HD73C1X5 Analog"
		alsa.subdevice = "0"
		alsa.subdevice_name = "subdevice #0"
		alsa.device = "0"
		alsa.card = "0"
		alsa.card_name = "HDA NVidia"
		alsa.long_card_name = "HDA NVidia at 0xf0b80000 irq 17"
		alsa.driver_name = "snd_hda_intel"
		device.bus_path = "pci-0000:00:08.0"
		sysfs.path = "/devices/pci0000:00/0000:00:08.0/sound/card0"
		device.bus = "pci"
		device.vendor.id = "10de"
		device.vendor.name = "NVIDIA Corporation"
		device.product.id = "0ac0"
		device.product.name = "MCP79 High Definition Audio"
		device.form_factor = "internal"
		device.string = "front:0"
		device.buffering.buffer_size = "65536"
		device.buffering.fragment_size = "32768"
		device.access_mode = "mmap+timer"
		device.profile.name = "analog-stereo"
		device.profile.description = "Analog Stereo"
		device.description = "Built-in Audio Analog Stereo"
		alsa.mixer_name = "IDT 92HD73C1X5"
		alsa.components = "HDA:111d7675,10280271,00100103 HDA:10de0007,10280271,00100100"
		module-udev-detect.discovered = "1"
		device.icon_name = "audio-card-pci"
	ports:
		analog-output-speaker: Speakers (priority 10000, latency offset 0 usec, available: unknown)
			properties:
				device.icon_name = "audio-speakers"
		analog-output-headphones: Headphones (priority 9000, latency offset 0 usec, available: unknown)
			properties:
				device.icon_name = "audio-headphones"
	active port: <analog-output-speaker>
barts@Mint ~ $ 

User avatar
bartszu
Level 4
Level 4
Posts: 361
Joined: Thu Aug 28, 2014 7:39 pm
Location: Eire

Re: Command to play sound through speakers when headphones on ?

Post by bartszu »

Selection_195.jpg
This thing would allow me to run script.
Actually simple "sleep 8h" would allow me to run script.
But what to put to my script ??

I guess I am working now on development of Linux Alarm clocks now .........LOL..../°)
Might actually write them request on GitHub /°)
User avatar
MrEen
Level 23
Level 23
Posts: 18343
Joined: Mon Jun 12, 2017 8:39 pm

Re: Command to play sound through speakers when headphones on ?

Post by MrEen »

bartszu wrote: Mon Mar 25, 2019 9:10 pm I am going thru your web site, you know tons more about that then me.
This is annoying Linux still needs tons of development.
Don't tell me there is no Alarm Clock for Linux capable of doing that ???

You see problem atm is that I use headphones now but my active port is still: active port: <analog-output-speaker>

Code: Select all

barts@Mint ~ $ pacmd list-sinks
1 sink(s) available.
  * index: 0
	name: <alsa_output.pci-0000_00_08.0.analog-stereo>
	driver: <module-alsa-card.c>
	flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
	state: RUNNING
	suspend cause: 
	priority: 9959
	volume: front-left: 29491 /  45% / -20.81 dB,   front-right: 29491 /  45% / -20.81 dB
	        balance 0.00
	base volume: 65536 / 100% / 0.00 dB
	volume steps: 65537
	muted: no
	current latency: 21.61 ms
	max request: 4 KiB
	max rewind: 64 KiB
	monitor source: 0
	sample spec: s16le 2ch 44100Hz
	channel map: front-left,front-right
	             Stereo
	used by: 5
	linked by: 5
	configured latency: 26.00 ms; range is 26.00 .. 371.52 ms
	card: 0 <alsa_card.pci-0000_00_08.0>
	module: 6
	properties:
		alsa.resolution_bits = "16"
		device.api = "alsa"
		device.class = "sound"
		alsa.class = "generic"
		alsa.subclass = "generic-mix"
		alsa.name = "92HD73C1X5 Analog"
		alsa.id = "92HD73C1X5 Analog"
		alsa.subdevice = "0"
		alsa.subdevice_name = "subdevice #0"
		alsa.device = "0"
		alsa.card = "0"
		alsa.card_name = "HDA NVidia"
		alsa.long_card_name = "HDA NVidia at 0xf0b80000 irq 17"
		alsa.driver_name = "snd_hda_intel"
		device.bus_path = "pci-0000:00:08.0"
		sysfs.path = "/devices/pci0000:00/0000:00:08.0/sound/card0"
		device.bus = "pci"
		device.vendor.id = "10de"
		device.vendor.name = "NVIDIA Corporation"
		device.product.id = "0ac0"
		device.product.name = "MCP79 High Definition Audio"
		device.form_factor = "internal"
		device.string = "front:0"
		device.buffering.buffer_size = "65536"
		device.buffering.fragment_size = "32768"
		device.access_mode = "mmap+timer"
		device.profile.name = "analog-stereo"
		device.profile.description = "Analog Stereo"
		device.description = "Built-in Audio Analog Stereo"
		alsa.mixer_name = "IDT 92HD73C1X5"
		alsa.components = "HDA:111d7675,10280271,00100103 HDA:10de0007,10280271,00100100"
		module-udev-detect.discovered = "1"
		device.icon_name = "audio-card-pci"
	ports:
		analog-output-speaker: Speakers (priority 10000, latency offset 0 usec, available: unknown)
			properties:
				device.icon_name = "audio-speakers"
		analog-output-headphones: Headphones (priority 9000, latency offset 0 usec, available: unknown)
			properties:
				device.icon_name = "audio-headphones"
	active port: <analog-output-speaker>
barts@Mint ~ $ 

That usually means you have a jack detection and/or pin config issue. You're actually lucky sound is working right now.

I believe what you want is possible, but I'm not certain we can get there without either a script of hundreds of lines or causing issues with currently playing sounds. The issue with currently playing sounds is most likely to be the biggest stumbling block. But I am going to try to figure it out. The agonizing part is the lack of simple-to-understand documentation.
User avatar
bartszu
Level 4
Level 4
Posts: 361
Joined: Thu Aug 28, 2014 7:39 pm
Location: Eire

Re: Command to play sound through speakers when headphones on ?

Post by bartszu »

No documentation again, well what a surprise.
So I guess we are in try it yourself game :°)
User avatar
bartszu
Level 4
Level 4
Posts: 361
Joined: Thu Aug 28, 2014 7:39 pm
Location: Eire

Re: Command to play sound through speakers when headphones on ?

Post by bartszu »

pacmd set-sink-port 0 analog-output-headphones

This change my output to headphones.
But this:

pacmd set-sink-port 0 analog-output-speakers && audacious example.mp3

Resets it to analog-output-speakers, but because headphones pin is in, sound plays thru them.
User avatar
MrEen
Level 23
Level 23
Posts: 18343
Joined: Mon Jun 12, 2017 8:39 pm

Re: Command to play sound through speakers when headphones on ?

Post by MrEen »

bartszu wrote: Mon Mar 25, 2019 9:48 pm pacmd set-sink-port 0 analog-output-headphones

This change my output to headphones.
But this:

pacmd set-sink-port 0 analog-output-speakers && audacious example.mp3

Resets it to analog-output-speakers, but because headphones pin is in, sound plays thru them.
Hmmm, that's interesting. Did the sound ALSO play through the speakers?

I found this app, indicator-sound-switcher, that might very well lead to being able to create what you're looking for. On the Issues tab, there a report about new sounds playing to the old port, so I'm thinking this might lead to the right solution.

I've got to head to bed in a few minutes, but I'll try to spend some time on it tomorrow.
User avatar
bartszu
Level 4
Level 4
Posts: 361
Joined: Thu Aug 28, 2014 7:39 pm
Location: Eire

Re: Command to play sound through speakers when headphones on ?

Post by bartszu »

MrEen wrote: Mon Mar 25, 2019 9:57 pm
Hmmm, that's interesting. Did the sound ALSO play through the speakers?
N0 !
User avatar
MrEen
Level 23
Level 23
Posts: 18343
Joined: Mon Jun 12, 2017 8:39 pm

Re: Command to play sound through speakers when headphones on ?

Post by MrEen »

Well, I'm afraid this is still over my head. That switcher script I linked to above has THOUSANDS of lines of code to make a simple little switcher.

It might be possible to get sox or paplay to do something, but it'll probably be the weekend before I can get a good idea on the feasibility of using those to accomplish what you want.

You might want to consider using a visual notification instead. notify-send -t 0 "Timer expired" "Your time is up!" in the command field would work. The -t 0 will make the notification stay on the screen until you click on it.
User avatar
bartszu
Level 4
Level 4
Posts: 361
Joined: Thu Aug 28, 2014 7:39 pm
Location: Eire

Re: Command to play sound through speakers when headphones on ?

Post by bartszu »

MrEen wrote: Tue Mar 26, 2019 4:52 pm You might want to consider using a visual notification instead. notify-send -t 0 "Timer expired" "Your time is up!" in the command field would work. The -t 0 will make the notification stay on the screen until you click on it.
Cool thing actually :°)
User avatar
bartszu
Level 4
Level 4
Posts: 361
Joined: Thu Aug 28, 2014 7:39 pm
Location: Eire

Re: Command to play sound through speakers when headphones on ?

Post by bartszu »

OMG I sorted it, it works :°)))))
Locked

Return to “Scripts & Bash”