I have run a timed task on my Raspberry Pi 4 using crontab to play local audio files.
00 20 * * * ~/Documents/mp3.py
It does work, and the music plays automatically in the background when the time comes.
The problem is that when music is played, the sound comes out of the HDMI speaker, not the Bluetooth speaker. The Bluetooth speaker is connected and working, and when I run this Python code in VS Code and Terminal, the sound is played through the Bluetooth speaker.
I did some reading and added the following to the crontab:
XDG_RUNTIME_DIR=/run/user/user_id
But it didn't work, when the crontab command was launched, there was still no sound from the Bluetooth speaker.
I don't know what else I can try.
Related
When HDMI cable is pluggwd in at the boot time, the Rasp Pi 4 display comes up normally and audio plays. (One can check by right clicking on the audio icon on the menu bar, to see the device profile in which HDMI is selected by default.)
Now even if you remove the HDMI cable and then replug it in, you will get back the normal display and the audio
However, if you boot up the Rasp Pi and plug in the HDMI cable later on, the display will come up but the audio will be missing. Right clicking on the audio icon of the Menu bar will reveal that HDMI is itself missing in the device profile.
I have tried out all permutation/ combinatioms of HDMI in the /boot/config.txt, but that doesn't help.
My Pi is normally supposed to be used as a Hotspot, but as an option, one can plug in a HDMI monitor anytime. Rebooting shouldn't be required to get the audio.
Note that there is, of course, no problem if there was a switched-off HDMI monitor connected at the boot time, Whenever one switches the monitor on, the display and the audio will be back.
The missing audio problem comes only when you connecr a HDMI monitor, later on.
After extensive trying out with the help from the raspberry pi forum (https://forums.raspberrypi.com/viewtopic.php?t=343523 ) following is the solution which works well.
In /etc/udev/rules.d/99-HDMICallback.sh keep this rule
KERNEL=="card?", SUBSYSTEM=="drm", ACTION=="change", RUN+="/home/pi/HDMICallback.sh"
In HDMICallback.sh keep this shell code
HDMIDetect(){
systemctl --user stop pulseaudio.service
systemctl --user stop pulseaudio.socket
pulseaudio --start
touch /tmp/HDMI.pr
}
export -f HDMIDetect
[ ! -f /tmp/HDMI.pr ] && [ "$(cat /sys/class/drm/card?-HDMI-A-1/status)" == "connected" ] && su pi -c "bash -c HDMIDetect"
Essentially the pulseaudio has to be stopped and then restarted, when the HDMI plugin triggers the HDMICalback.sh.
Once the pulseaudio has been started, then the same doesn't have to be done, on subsequent HDMI plugouts and plugins - hence the /tmp/HDMI.pr variable.
Unlike a PC, Raspberry PI can be started without a HDMI Monitor attached, perhaps for serving in a headless way or with a hnotspot. At any point an HDMI monitor can be attached with the display and audio coming up immediately.
i hava following project, which i want to execute:
I want to add a Microphone on my Raspberry. After, i want to connect my raspberry over Bluetooth to my Phone/Computer. My goal is, to speak in the Microphone and the spoken Sound is sent to my Phone, which can be used as a Soundsource to response my friends on call or someting like this. So, it should act like a Handsfree facility. is this possible? Till now, i only heard of sending audio to my raspberry over bluetooth and put it out on a speaker on a raspberry, but i this project i want exactly the opposite. Can someone help me, to find a soulution? thanks
I would like to play audio on my raspberry pi, the audio player (console application) should in a docker container. I have seen multiple articles on the web, they commonly suggest to add the --device /dev/snd to the docker run. I just can't seem to get the audio through. Audio should be played on the device that's attached via HDMI cable. I tried sox player, I took ubuntu 18.04 as base image and also this sample solution. I'm flexible with with what the media player application is as this is a hobby project (would be nice that I can "pipe" an mp3 file to the program via bash while it is being streamed from somewhere). On the host I recently installed "Raspberry Pi OS with desktop and recommended software". (Release date is October 30th 2021, Kernel version: 5.10, whatever came with it). Pi 2 model B 1.1 (2014).
UPDATE: Audio does play on 3.5mm jack
It seems that by using the --device /dev/snd option, audio does play on the 3.5mm jack. I don't know though how to make this work on the HDMI.
I would like to stream my music through my Bluetooth speaker but PulseAudio can't see the speaker. When I open the sound settings (pavucontrol) I can't change the output device to my speaker since it's not displayed.
What I already checked
The speaker is paired and connected through the Bluetooth interface in GNOME. I verified the connection using the bluetoothctl tool and made sure that the device is connected and trusted by OpenSUSE.
I checked if PulseAudio can see the device through the command line using pactl list sources short and pactl list sinks short and it's not there either.
I verified if PulseAudio has the right Bluetooth addon installed and it has.
Removing the configuration in ~/.config/pulse doesn't help
This question: Pulseaudio not detecting bluetooth headset couldn't help me either.
It worked a couple months ago without any issue but now it doesn't. Any advice to force PulseAudio to recognize my Bluetooth speaker?
Setup:
UE Boom Bluetooth speaker
GNOME OpenSUSE Leap 15.0
Pulseaudio 11.1
BlueZ 5.48
Try these steps to resolve the bluetooth audio issue on Opensuse Linux- These would work in ubuntu and other linux too. I am running on Opensuse linux 15.
First comment out the line
load-module module-bluetooth-discover
by editing the
sudo vim /etc/pulse/default.pa
Now you would need to reboot after this change is done. After rebooting,
we configure the bluetoothctl by running the following sequence of commands in a terminal:
> pactl load-module module-bluetooth-discover
> bluetoothctl
>> power on
>> agent on
>> default-agent
>> discoverable on
>> scan on
scanon will return with the name of the bluetooth speaker along with a code in the format '11:11:11:11:11:11' - thats ur bluetoooth speakers id. Note that down and use it in the next command trust and connect.
>> trust 11:11:11:11:11:11
>> connect 11:11:11:11:11:11
>> scan off
Do not close this terminal.
And these are all thats required to connect to a bluetooth speaker/headphone.
YOu can put the above in a script say - connectbluettooth.sh and run it everytime you login.
Last step change the speakers settings, your applications uses by running the below command:-
pavucontrol - Change the default audio device to the bluetooth speaker.
You can see my bluetooth speaker - 'Juarez' set in the pavucontrol tool in the screenshot.
I got an Arduino nano V3.0, connected via USB to my computer, and powered with the USB.
I want to use the nano to send a signal over the USB to the computer when it detects a sound of some amplitude.
Anybody knows how to connect a sound sensor to nano as easily as possible?
thanks
rough
I found this link useful http://arduinobasics.blogspot.com/2013/05/sound-sensor.html. Just connect sensor to arduino and adopt code for your needs (you don't need leds, just sensor). To send sensor status over USB use Serial class on Arduino and terminal application on PC.
You have 2 options, one of them is to buy a microphone which outputs a pulse when sound exceeds the threshold you've set on the potentiometer on the board, for example this one: Microphone Detector
The other option is to buy a microphone which outputs an analog stream which can be read by the A0 port on the Arduino Nano.
This Adafruit link can help you understand the code. As you can see, the analogRead(0); reads the A0 port of the arduino.