View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

How to Record and Play Audio

Team Robot Chicken

How to Record and Play Audio

Uploaded Image: RobotChicken.jpg
by: Amro Mousa, Elliott Clark, Brandon Reynolds, Jiasheng He


Recording
First, you need an object that has the actual recorded sound. This can be done by declaring a SoundRecorder variable.
audio:=SoundRecorder new.
You then need to declare two boolean objects, one as a recording flag and the other to tell the program that there is a stored recording.
recording:=false
recorded:=false
Decide when you want to start recording (whether it be on a button press, at the beginning of a series of actions, etc). Write a toggle recording function to be called at that time that can both start and stop recording. This function should change both recording variable to true, and then start the recording. The actual recording part is simply done by clearing the previous sound and then recording the new one. In the following example, the page object has an audio object.
recording := recording not.
recorded := true.
recording
ifTrue: [
	page getAudio clearRecordedSound.
	page getAudio resumeRecording.
	].
Playback
Playback is very similar to recording, but with different variables and function calls.
First, initialize a playback flag.
playing := false.
For the playback function, which again can be used to both start and stop playback, you need to check if there's something recorded. If there is something recorded, change the playback variable. Actual playback is handled by a simple playback function call on the SoundRecorder object. In the following example, the book object's page object holds the SoundRecorder object.
recorded
ifTrue: [
	playing := playing not.
	playing
	ifTrue: [
		book currentPage getAudio playback.
	].
].
A full implementation of sound recording for a BookMorph subclass can be found in Team Robot Chicken's Cases Page. For the specific functions mentioned, check out the TimedPage and TimerMorph classes.

For another example of how to use Audio, check out the AudioNotes add-on, and the AudioNotes lecture slides.

Links to this Page