Please note: Friday June 18 is a holiday celebrating Juneteenth, please allow extra time for your order to arrive and plan accordingly.
0

Play Wav/Mp3 through Voice Bonnet Speaker
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Please be positive and constructive with your questions and comments.

Play Wav/Mp3 through Voice Bonnet Speaker

by piornet on Sun Feb 14, 2021 12:41 am

Hi! I'm trying to play an audio file through the voice bonnet, but having problems. I'm using it on an Rpi4 - not sure how to configure playback through the speakers connected to the bonnet. Any help would be appreciated. I'm using Pygame, but not married to it - just need to figure out a way to get it play through the attached speakers.

Thanks so much!

piornet
 
Posts: 11
Joined: Mon Mar 25, 2013 9:07 pm

Re: Play Wav/Mp3 through Voice Bonnet Speaker

by mikeysklar on Mon Feb 15, 2021 6:05 pm

piornet,

Did you follow our guide for the Voice Bonnet setup on your Pi4?

https://learn.adafruit.com/adafruit-voi ... y-pi-setup

mikeysklar
 
Posts: 4576
Joined: Mon Aug 01, 2016 8:10 pm

Re: Play Wav/Mp3 through Voice Bonnet Speaker

by piornet on Fri Feb 19, 2021 12:48 pm

Yes, and I was able to hear the sounds. But when I try playing a WAV file through pygame, I don't hear anything. (I've double-checked to make sure the audio switch is set to ON).

I'm using an RPi4 so the bonnet is card 2.

piornet
 
Posts: 11
Joined: Mon Mar 25, 2013 9:07 pm

Re: Play Wav/Mp3 through Voice Bonnet Speaker

by mikeysklar on Mon Feb 22, 2021 6:40 pm

I noticed on our pygame examples we are providing MP3 files. Are you able to play those?

https://learn.adafruit.com/adafruit-spe ... ith-pygame

Are you using pygameMP3.py we provide?

Code: Select all | TOGGLE FULL SIZE
''' pg_midi_sound101.py
play midi music files (also mp3 files) using pygame
tested with Python273/331 and pygame192 by vegaseat
'''
#code modified by James DeVito from here: https://www.daniweb.com/programming/software-development/code/454835/let-pygame-play-your-midi-or-mp3-files


#!/usr/bin/python

import sys
import pygame as pg
import os
import time


def play_music(music_file):
    '''
    stream music with mixer.music module in blocking manner
    this will stream the sound from disk while playing
    '''
    clock = pg.time.Clock()
    try:
        pg.mixer.music.load(music_file)
        print("Music file {} loaded!".format(music_file))
    except pygame.error:
        print("File {} not found! {}".format(music_file, pg.get_error()))
        return

    pg.mixer.music.play()
   
    # If you want to fade in the audio...
    # for x in range(0,100):
    #     pg.mixer.music.set_volume(float(x)/100.0)
    #     time.sleep(.0075)
    # # check if playback has finished
    while pg.mixer.music.get_busy():
        clock.tick(30)


freq = 44100    # audio CD quality
bitsize = -16   # unsigned 16 bit
channels = 2    # 1 is mono, 2 is stereo
buffer = 2048   # number of samples (experiment to get right sound)
pg.mixer.init(freq, bitsize, channels, buffer)


if len(sys.argv) > 1:

    try:
        user_volume = float(sys.argv[1])
    except ValueError:
        print "Volume argument invalid. Please use a float (0.0 - 1.0)"
        pg.mixer.music.fadeout(1000)
        pg.mixer.music.stop()
        raise SystemExit

    print("Playing at volume: " + str(user_volume)+ "\n")
    pg.mixer.music.set_volume(user_volume)
    mp3s = []
    for file in os.listdir("."):
        if file.endswith(".mp3"):
            mp3s.append(file)

    print mp3s

    for x in mp3s:
        try:
            play_music(x)
            time.sleep(.25)
        except KeyboardInterrupt:
            # if user hits Ctrl/C then exit
            # (works only in console mode)
            pg.mixer.music.fadeout(1000)
            pg.mixer.music.stop()
            raise SystemExit
else:
    print("Please specify volume as a float! (0.0 - 1.0)")

mikeysklar
 
Posts: 4576
Joined: Mon Aug 01, 2016 8:10 pm

Re: Play Wav/Mp3 through Voice Bonnet Speaker

by piornet on Tue Feb 23, 2021 6:57 pm

Unfortunately pygameMP3.py produces a syntax error:

download.png
download.png (154.99 KiB) Viewed 201 times

piornet
 
Posts: 11
Joined: Mon Mar 25, 2013 9:07 pm

Re: Play Wav/Mp3 through Voice Bonnet Speaker

by mikeysklar on Wed Feb 24, 2021 3:34 pm

I see your point about pygameMP3 having some issues. I downloaded on my OS/X and a Pi4 machine with similar results that you saw.

How about using the classic mpg123 for MP3s or aplay for WAVs

I'm assuming you are running the current Pi OS release with updates is that correct?

alsamixer should still control volume levels

mikeysklar
 
Posts: 4576
Joined: Mon Aug 01, 2016 8:10 pm

Re: Play Wav/Mp3 through Voice Bonnet Speaker

by piornet on Fri Mar 19, 2021 9:19 pm

Unfortunately that didn't work either. I ordered another Voice Bonnet hat just in case it's a hardware issue, as I saw another post about that. Will give that a try.

piornet
 
Posts: 11
Joined: Mon Mar 25, 2013 9:07 pm

Re: Play Wav/Mp3 through Voice Bonnet Speaker

by piornet on Tue Mar 23, 2021 1:54 pm

I got the new board but unfortunately it's the same problem. I'm not sure what to do - my project is stuck without the speakers working. Do you have any suggestions?

piornet
 
Posts: 11
Joined: Mon Mar 25, 2013 9:07 pm

Re: Play Wav/Mp3 through Voice Bonnet Speaker

by mikeysklar on Wed Mar 24, 2021 1:36 pm

Just to summarize where we are.

Every aspect of the Audio Setup page is working correctly?

https://learn.adafruit.com/adafruit-voi ... udio-setup

aplay / alsamixer / speaker-test -c2 / arecord are all working properly through the speakers connected to the voice bonnet 3.5" jack?

The only part that is not working is pygame?

mikeysklar
 
Posts: 4576
Joined: Mon Aug 01, 2016 8:10 pm

Re: Play Wav/Mp3 through Voice Bonnet Speaker

by piornet on Mon Mar 29, 2021 11:17 am

No, I'm not able to get any sound from it at all, including speaker test and the microphone test.

What I've done:
* Formatted card and tried a fresh install and followed all the instructions again
* Purchased another Voice Bonnet in case my board was bad

piornet
 
Posts: 11
Joined: Mon Mar 25, 2013 9:07 pm

Re: Play Wav/Mp3 through Voice Bonnet Speaker

by mikeysklar on Tue Mar 30, 2021 5:00 pm

Okay, since nothing works let's back up a step from audio configuration and get you running the blinka installation script that will setup i2c. Then we can confirm you can see the device.

Code: Select all | TOGGLE FULL SIZE
cd ~
sudo pip3 install --upgrade adafruit-python-shell
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.py
sudo python3 raspi-blinka.py


https://learn.adafruit.com/adafruit-voi ... inka-setup

Code: Select all | TOGGLE FULL SIZE
sudo i2cdetect -y 1


https://learn.adafruit.com/adafruit-voi ... udio-setup

mikeysklar
 
Posts: 4576
Joined: Mon Aug 01, 2016 8:10 pm

Re: Play Wav/Mp3 through Voice Bonnet Speaker

by mikeysklar on Tue Mar 30, 2021 5:01 pm

Okay, since nothing works let's back up a step from audio configuration and get you running the blinka installation script that will setup i2c. Then we can confirm you can see the device.

Code: Select all | TOGGLE FULL SIZE
cd ~
sudo pip3 install --upgrade adafruit-python-shell
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.py
sudo python3 raspi-blinka.py


https://learn.adafruit.com/adafruit-voi ... inka-setup

Code: Select all | TOGGLE FULL SIZE
sudo i2cdetect -y 1


https://learn.adafruit.com/adafruit-voi ... udio-setup

mikeysklar
 
Posts: 4576
Joined: Mon Aug 01, 2016 8:10 pm

Re: Play Wav/Mp3 through Voice Bonnet Speaker

by piornet on Sun Apr 11, 2021 2:16 pm

Thanks for the reply! I've redone the Blinka installation and confirmed that the device is showing up. It shows up as UU, I've attached a screenshot. Still no sound from either the attached speaker or from headphones on both the Voice Bonnet and on the Pi4 itself. :(


mikeysklar wrote:Okay, since nothing works let's back up a step from audio configuration and get you running the blinka installation script that will setup i2c. Then we can confirm you can see the device.

Code: Select all | TOGGLE FULL SIZE
cd ~
sudo pip3 install --upgrade adafruit-python-shell
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.py
sudo python3 raspi-blinka.py


https://learn.adafruit.com/adafruit-voi ... inka-setup

Code: Select all | TOGGLE FULL SIZE
sudo i2cdetect -y 1


https://learn.adafruit.com/adafruit-voi ... udio-setup
Attachments
download.png
download.png (60.01 KiB) Viewed 81 times

piornet
 
Posts: 11
Joined: Mon Mar 25, 2013 9:07 pm

Re: Play Wav/Mp3 through Voice Bonnet Speaker

by mikeysklar on Mon Apr 12, 2021 3:47 pm

The UU part is great. You see the Bonnet.

What happens when you run the following steps. I'm assuming you are on the latest Pi OS release kernel of 5.10. If you are not please update your installation.

https://learn.adafruit.com/adafruit-voi ... udio-setup

Code: Select all | TOGGLE FULL SIZE
 cd ~
sudo apt-get install -y git
git clone https://github.com/HinTak/seeed-voicecard
cd seeed-voicecard
git checkout v5.9
sudo ./install.sh
sudo reboot

and on reboot run

sudo aplay -l
speaker-test -c2

mikeysklar
 
Posts: 4576
Joined: Mon Aug 01, 2016 8:10 pm

Re: Play Wav/Mp3 through Voice Bonnet Speaker

by piornet on Mon Apr 12, 2021 7:41 pm

I repeated the steps, and it still shows up.
Attachments
download.png
download.png (89.57 KiB) Viewed 71 times

piornet
 
Posts: 11
Joined: Mon Mar 25, 2013 9:07 pm

Please be positive and constructive with your questions and comments.