![Adafruit UDA1334A Manual Download Page 30](http://html1.mh-extra.com/html/adafruit/uda1334a/uda1334a_manual_2845855030.webp)
Play Audio with PyGame
You can use mpg123 for basic testing but it's a little clumsy for use where you want to dynamically change the volume
or have an interactive program. For more powerful audio playback we suggest using PyGame to playback a variety of
audio formats (MP3 included!)
Install PyGame
Start by installing pygame support, you'll need to open up a console on your Pi with network access and run:
Next, download this pygame example zip to your Pi
https://adafru.it/wbp
https://adafru.it/wbp
On the command line, run
wget
https://cdn-learn.adafruit.com/assets/assets/000/041/506/original/pygame_example.zip
(https://adafru.it/wbq)
unzip
pygame_example.zip
(https://adafru.it/wbq)
Run Demo
Inside the zip is an example called pygameMP3.py
This example will playback all MP3's within the script's folder. To demonstrate that you can also adjust the volume
within pygame, the second argument is the volume for playback. Specify a volume to playback with a command line
argument between 0.0 and 1.0
For example here is how to play at 75% volume:
Here's the code if you have your own mp3s!
sudo apt-get install python-pygame
python pygameMP3.py 0.75
''' 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
© Adafruit Industries
https://learn.adafruit.com/adafruit-i2s-stereo-decoder-uda1334a
Page 30 of 45