Can Mycodo play sound files?

Can Mycodo play a sound file .wav / .mp3 (of birdsong) when the grow lights turn on?

There is some discussion if music or birdsong is beneficial to the growth and health of plants. Actually, it is quite relaxing for me to zip open the tent and hear the birdsong sound file playing.

I have my grow lights declared as an output

I have a function (Trigger: Timer Daily Point) to turn on the grow lights for a specific duration.

Is it possible to have the same time function applied to a sound file?

Sure, you should be able to play most basic audio files with aplay. If using a Function, just use the Linux Command Action and that will allow you to execute any linux shell command. For outputs, there’s the Shell Script (On/Off) output that can also have any command used when it’s turned on or off. The Function Action is the preferred method.

Thanks for the suggestion.

I have no experience programming, but I started reading how to create a shell file that will run the sound file via an output from a function.

However, I am receiving the following error message, and no amount of searching has given me any solutions:

2021-10-25 09:33:26,300 - DEBUG - mycodo.outputs.on_off_shell_c39c8c47 - output_on_off(on, 0, sec, 39600.0, 0.0, True)
2021-10-25 09:33:26,410 - DEBUG - mycodo.outputs.on_off_shell_c39c8c47 - Output on/off on command returned: Status: 1, Output: 'b''', Error: 'b"Failed to create secure directory (/home/mycodo/.config/pulse): No such file or directory\nALSA lib confmisc.c:767:(parse_card) cannot find card '0'\nALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory\nALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings\nALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory\nALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name\nALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory\nALSA lib conf.c:5047:(snd_config_expand) Evaluate error: No such file or directory\nALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM default\naplay: main:828: audio open error: No such file or directory\n"'
2021-10-25 09:33:26,412 - DEBUG - mycodo.outputs.on_off_shell_c39c8c47 - Output c39c8c47-131e-44a2-8314-3f5d08d54c09 CH0 (Birdsong) on for 39600.0 seconds. Output returned: None

This is my setup to run the sound file:

I set up the output as show below:

My script_on.sh file reads as follows:

#! /bin/bash
aplay /home/pi/Birdsong1.wav

My script_off.sh file reads as follows:

#! /bin/bash
killall aplay

I have given the following read, write and execute permissions to the files, as follows:

I then added the output to be triggered by a function, as follows:

I tried many different solutions, but my system started behaving oddly, so I had to re-image the SD card with Rasbian and Mycodo and start over.

I am uncertain if I have made 1 mistake or a series of mistakes, so if anyone can shed light to solving this error, that would be great.

All of my Pis I’ve tested with plain Raspbian OS can play audio files from the command line without issue. Can you play the audio file from the command line when logged in to a terminal? Try running sudo raspi-config and selecting System Options → Audio and selecting an output device for your audio. You were trying to execute a file in /home/pi with the user “mycodo”, which likely doesn’t have permission. Try changing the user to “pi” or “root”. If none of that works, try a search with the errors you received with the term “Raspberry Pi” to find users with similar issues.

Here’s the test file I was using: sample.wav

pi@reterm:~ $ aplay sample.wav
Playing WAVE 'sample.wav' : Unsigned 8 bit, Rate 22050 Hz, Mono

The first issue I checked was that the wave sound files do correctly play from the command line.

I changed the user name to pi & root, and Mycodo will still not play the wave sound files.

I also ran alsamixer from the command line and confirmed the volume levels of the audio.

Additionally, I ran sudo raspi-config and selected System Options → Audio and confirmed the output device for the audio.

I searched extensively for a solution, but there appears to no solution for this issue.

I tried different types of wave files (stereo / mono, signed / unsigned, 8 bit / 16 bit, and different hertz) and still no sound files are played by Mycodo.

Here is the log showing the error for the attempt to play the sample.wav file Kyle provided:

[Trigger 54e9ae75-d7ae-495c-a454-1463ea64d4c9 (Test Soundfile Function)]
[Action b8146440, Output (On/Off/Duration)]: Turn output 5e50484a-dfd5-4074-ae01-adb96bdfd242 CH56b8a903-7787-4f88-a1ea-44509a40ea47 (6, Test Soundfile Output) on for 20.0 seconds.
2021-10-25 13:29:00,228 - DEBUG - mycodo.outputs.on_off_shell_5e50484a - output_on_off(on, 0, sec, 20.0, 0.0, True)
2021-10-25 13:29:06,669 - DEBUG - mycodo.outputs.on_off_shell_5e50484a - Output on/off on command returned: Status: 0, Output: 'b''', Error: 'b"Playing WAVE '/home/pi/sample.wav' : Unsigned 8 bit, Rate 22050 Hz, Mono\n"'
2021-10-25 13:29:06,670 - DEBUG - mycodo.outputs.on_off_shell_5e50484a - Output 5e50484a-dfd5-4074-ae01-adb96bdfd242 CH0 (Test Soundfile Output) on for 20.0 seconds. Output returned: None
2021-10-25 13:29:20,237 - DEBUG - mycodo.outputs.on_off_shell_5e50484a - output_on_off(off, 0, None, 0.0, 0.0, True)
2021-10-25 13:29:20,284 - DEBUG - mycodo.outputs.on_off_shell_5e50484a - Output on/off off command returned: Status: 1, Output: 'b''', Error: 'b'aplay: no process found\n''
2021-10-25 13:29:20,284 - DEBUG - mycodo.outputs.on_off_shell_5e50484a - Output 5e50484a-dfd5-4074-ae01-adb96bdfd242 CH0 (Test Soundfile Output) OFF at 2021-10-25 13:29:20. Output returned: None

Strangely, when I use a stereo 16-bit wav sound file, Mycodo does not play the sound file and no error in the log is displayed. Here it is:

2021-10-25 13:52:00,328 - DEBUG - mycodo.trigger_action_b8146440 - Message: 2021-10-25 13:52:00
[Trigger 54e9ae75-d7ae-495c-a454-1463ea64d4c9 (Test Soundfile Function)]
[Action b8146440, Output (On/Off/Duration)]: Turn output 5e50484a-dfd5-4074-ae01-adb96bdfd242 CH56b8a903-7787-4f88-a1ea-44509a40ea47 (6, Test Soundfile Output) on for 20.0 seconds.
2021-10-25 13:52:00,328 - DEBUG - mycodo.trigger_action_b8146440 - Note Tags: []
2021-10-25 13:52:00,329 - DEBUG - mycodo.trigger_action_b8146440 - Email Recipients: []
2021-10-25 13:52:00,329 - DEBUG - mycodo.trigger_action_b8146440 - Attachment Files: None
2021-10-25 13:52:00,329 - DEBUG - mycodo.trigger_action_b8146440 - Attachment Type: None
2021-10-25 13:52:00,330 - DEBUG - mycodo.trigger_function_actions_54e9ae75 - Message: 2021-10-25 13:52:00
[Trigger 54e9ae75-d7ae-495c-a454-1463ea64d4c9 (Test Soundfile Function)]
[Action b8146440, Output (On/Off/Duration)]: Turn output 5e50484a-dfd5-4074-ae01-adb96bdfd242 CH56b8a903-7787-4f88-a1ea-44509a40ea47 (6, Test Soundfile Output) on for 20.0 seconds.
2021-10-25 13:52:00,333 - DEBUG - mycodo.outputs.on_off_shell_5e50484a - output_on_off(on, 0, sec, 20.0, 0.0, True)

I’m able to play wav files with a fresh install of Raspbian. Perhaps you should reflash or install Raspbian, if you’re using a different OS.

I don’t believe you mentioned that you attempted to play a wav from the command line like I suggested.

I re-installed Rasbian and Mycodo yesterday after I had the same issue with Mycodo playing wave sound files.

The problem continues with the fresh install.

Running the script_on.sh shell file from the command line plays the wave sound files. Running the sound files directly from the command line plays the wave sound files.

Playing the sound files and the shell files from Mycodo appears to be the issue.

I would be curious if you could play the wave sound file from a Mycodo function.

Perhaps you should try another method, such as the Python Code (On/Off) output and use a python library to play the file.

Another method could be to create a Conditional Controller function and develop Python code to play the audio, then use Activation and Deactivation of the Conditional Controller to start and stop the playback.

I have tried both of your latest suggestions and both do not work.

I think we can assume Mycodo cannot play sound files.

I’m sure it’s possible. There are many command line audio players and Python libraries to play audio files. Just because one doesn’t work, doesn’t mean they all don’t. I don’t currently have time to experiment, but there is likely a solution that doesn’t involve changing the Mycodo code base.