Orange Pi Zero 2W as MPD media player: only static noise with mp3 files

I am using an Orange Pi Zero 2W with an Orange Pi Expansion Board, with a speaker connected to the Expansion board 3,5 mm audio output.
The current OS on the Orange Pi is Orange Pi Debian Bookworm Server v 1.0.2
It is connected to the LAN via the ethernet connection.

I am now trying to use it as a MPD media player in Home Assistant, following this example:
Raspberry Pi Zero W as a media_player for Home Assistant
The idea is to use this setup as a media player with Voice Assistant.
So I installed alsa-utils and mpd, and than I could successfully play local wav files through the speaker with aplay.
In Home Assistant I did add the MPD integration, which successfully connected to the Orange Pi, and I can play wav files from the HA Media Player.

However, the problem is that when I play some mp3 sound from Home Assistant via the MPD media Player I only hear a loud static noise.
This is both with playing a mp3 directly from the media player interface, and with playing some spoken text via Piper TTS.
And I also cannot play mp3 files locally via aplay.
The duration of the sound seems to correspond to the original file, so it looks like the mp3 is transferred to the Orange Pi, but not correctly decoded?

Then I tried many different settings for MPD, added all by apt install MPD recommended and suggested packages, and added extra packages, like ffmpeg, mplayer, but unfortunately it still doesn’t work.
I can now play mp3 files locally with mplayer, but it still does not work with aplay and MPD.
So this must be some misconfiguration in MPD?

This is the current MPD configuration in etc/mpd.conf:

music_directory         "/var/lib/mpd/music"
playlist_directory              "/var/lib/mpd/playlists"
db_file                 "/var/lib/mpd/tag_cache"
#log_file                       "/var/log/mpd/mpd.log"
#pid_file                       "/run/mpd/pid"
state_file                      "/var/lib/mpd/state"
sticker_file                   "/var/lib/mpd/sticker.sql"
bind_to_address                 "localhost"
# Permissions #################################################################
#password                        "password@read,add,control,admin"
default_permissions             "read,add,control,admin"
# Input #######################################################################
input {
        plugin "curl"
#       proxy "proxy.isp.com:8080"
#       proxy_user "user"
#       proxy_password "password"
}
# Decoder #####################################################################
decoder {
        plugin                  "hybrid_dsd"
        enabled                 "no"
#       gapless                 "no"
}
decoder {
        plugin        "wildmidi"
        enabled       "no"
        #config_file "/etc/timidity/timidity.cfg"
}
decoder {
        plugin       "mad"
        enabled      "yes"
}
# Audio Output ################################################################
audio_output {
        type            "alsa"
        name            "OPZ2W ALSA Device"
        device          "hw:0,0"        # optional
        mixer_type      "hardware"      # optional
        mixer_device    "default"       # optional
        mixer_control   "PCM"           # optional
##      mixer_index     "0"             # optional
}

I tried lots of different combinations of the above MPD settings, unfortunately to no avail.

This is what I got in the local MPD logs:

> Feb 12 13:56:42 opz2w-1 mpd[1205]: exception: CURL failed: The requested URL returned error: 404
> Feb 12 13:56:42 opz2w-1 mpd[1205]: exception: CURL failed: The requested URL returned error: 404
> Feb 12 13:56:42 opz2w-1 mpd[1205]: exception: CURL failed: The requested URL returned error: 404
> Feb 12 13:56:46 opz2w-1 mpd[1205]: player: played "http://192.168.124.50:8123/api/tts_proxy/rBBlJaIF1jf6R7Q31t_sPw.mp3"

And this are some examples of what I got in the Home Assistant logs:

Logger: homeassistant.components.tts
Source: components/tts/__init__.py:1099
integration: Text-to-speech (TTS) (documentation, issues)
First occurred: 08:43:39 (21 occurrences)
Last logged: 12:11:05

Error on load tts: cover.png was not recognized!
Error on load tts: cover.jpg was not recognized!
Error on load tts: cover.webp was not recognized!

Logger: homeassistant.components.media_player
Source: helpers/entity_platform.py:1039
integration: Media player (documentation, issues)
First occurred: 14:31:21 (10 occurrences)
Last logged: 14:54:33

Updating mpd media_player took longer than the scheduled update interval 0:00:10

Logger: homeassistant.components.mpd
Source: components/mpd/media_player.py:156
integration: Music Player Daemon (MPD) (documentation, issues)
First occurred: 14:31:46 (4 occurrences)
Last logged: 14:54:38

Error connecting to '192.168.124.215': Connection attempt timed out
Error connecting to '192.168.124.215': [Errno 113] Connect call failed ('192.168.124.215', 6600)

Logger: homeassistant.helpers.entity
Source: helpers/entity.py:1288
First occurred: 14:31:21 (6 occurrences)
Last logged: 15:13:21

Update of media_player.music_player_daemon is taking over 10 seconds

Logger: homeassistant.components.http.ban
Source: components/http/ban.py:136
integration: HTTP (documentation, issues)
First occurred: 15:06:37 (6 occurrences)
Last logged: 15:13:42

Login attempt or request with invalid authentication from 192.168.124.215 (192.168.124.215). Requested URL: '/media/local/cover.png'. (Music Player Daemon 0.23.12)
Login attempt or request with invalid authentication from 192.168.124.215 (192.168.124.215). Requested URL: '/media/local/cover.jpg'. (Music Player Daemon 0.23.12)
Login attempt or request with invalid authentication from 192.168.124.215 (192.168.124.215). Requested URL: '/media/local/cover.webp'. (Music Player Daemon 0.23.12)

Those errors seem to be related to this issue. However, that seems to be about media art that cannot be downloaded, and that should not stop the mp3 from playing I would say?

Has anybody experience with this setup?

OK, I found the solution!

In the end it appeared that the ALSA audio output format was not correctly defined by default.
I had to add format “44100:16:2" to the ALSA audio_output settings.

This is the working MPD configuration for the 3,5 mm analogue output of the Orange Pi Zero 2W with the Expansion Board:

music_directory         "/var/lib/mpd/music"
playlist_directory              "/var/lib/mpd/playlists"
db_file                 "/var/lib/mpd/tag_cache"
#log_file                       "/var/log/mpd/mpd.log"
#pid_file                       "/run/mpd/pid"
state_file                      "/var/lib/mpd/state"
sticker_file                   "/var/lib/mpd/sticker.sql"
bind_to_address                 "localhost"
# Permissions #################################################################
#password                        "password@read,add,control,admin"
default_permissions             "read,add,control,admin"
# Input #######################################################################
input {
        plugin "curl"
#       proxy "proxy.isp.com:8080"
#       proxy_user "user"
#       proxy_password "password"
}
# Decoder #####################################################################
decoder {
        plugin                  "hybrid_dsd"
        enabled                 "no"
#       gapless                 "no"
}
decoder {
        plugin        "wildmidi"
        enabled       "no"
        #config_file "/etc/timidity/timidity.cfg"
}
# Audio Output ################################################################
audio_output {
        type            "alsa"
        name            "OPZ2W ALSA Device"
        device          "hw:0,0"        # optional
        format          "44100:16:2" 
##      mixer_type      "hardware"      # optional
##      mixer_device    "default"       # optional
##      mixer_control   "PCM"           # optional
##      mixer_index     "0"             # optional
}

Like this I can access the MPD media Player from Home Assistant, and use it with Piper TTS.

One more update: it appeared that there was no volume control available with the MPD settings as shown in my previous post. It was only possible to modify the volume when running the alsamixer locally in the Orange Pi.
However, I found a solution for this with one additional setting for the MPD ALSA output.
By default the mixer_control setting is “PCM”, but after I changed this into “LINEOUT volume” the volume control came available via the Home Assistant MPD Media Player.

This this my current ALSA audio_output for MPD:

# Audio Output ################################################################
audio_output {
        type            "alsa"
        name            "OPZ2W ALSA Device"
        device          "hw:0,0"        # optional
        format          "44100:16:*"
        mixer_type      "hardware"      # optional
##      mixer_device    "default"       # optional
        mixer_control   "LINEOUT volume"                # optional
##      mixer_index     "0"             # optional
}

One more update for completeness: the sound through the analogue 3,5 mm output of the Expansion Board was of somewhat low quality, especially when compared to the sound quality through the HDMI output. It sounded a little distorted.
Again trying all kind of settings for the MPD configuration it appeared that it is better in this case to set the mixer_type as “software” instead of “hardware”.

And it also appeared that the initial problem with the static noise instead of normal sound was solely depending on the bit rate missing from the default config. It did not matter which sample-rate or number of channels was specified.
So it is enough to specify the format as “*:16:*”, which means that the sample rate and number of channels are not enforced.

So for reference, this is my (hopefully) final ALSA audio_output for MPD:

# Audio Output ################################################################
audio_output {
        type            "alsa"
        name            "OPZ2W ALSA Device"
        device          "hw:0,0"        # optional
        format          "*:16:*"
        mixer_type      "software"      # optional
##      mixer_device    "default"       # optional
        mixer_control   "LINEOUT volume"                # optional
##      mixer_index     "0"             # optional
}