logo
TOOLS TO HELP YOU LEARN
teachers, students, everyone
Tools | Blog | Account | Learn

Install the following to get sound up and running

sudo apt-get update
sudo apt-get upgrade

These are already installed, but for reference:
sudo apt-get install sox
sudo apt-get install espeak
sudo apt-get intall alsa
sudo apt-get install alsa-utils
omxplayer

To be able to play MP3s install this
sudo apt-get install libsox-fmt-mp3

sudo raspi-config
—> advanced
—> use 3.5 headphone jack

omxplayer vid.mov —loop

Need a mic to run following Python code

import os

os.system("sox -t alsa plughw:1 -d pitch 500")

PLAY SOUND

Open Idle
Add following code. Replace file name with the audio file you uploaded to your directory

import pygame, sys
from pygame.locals import *

 

#Main function
def main():
pygame.init()
pygame.mixer.init()
pygame.mixer.music.load("cool.mp3")
pygame.mixer.music.play()
while pygame.mixer.music.get_busy() == True:
continue

if __name__=='__main__':
main()

Run commands through python code:

import os

os.system("sudo python scale1.py")

============================
TASK 1: Get the pi to speak using the following command:
espeak “Hello, World”
============================
TASK 2:
If you Pi has a microphone you can try these fun commands

play cool.mp3
creepy villain
sox -t alsa plughw:1 -d pitch -500

High pitched surf voice
sox -t alsa plughw:1 -d pitch 500

To record audio:
rec −t alsa plughw:1 radio.aiff trim 0 10

RECORD AUDIO
arecord -D plughw:1,0 -f cd test.wav -d 10//records for ten seconds

PLAY AUDIO
aplay test.wav //this can also play mp3’s