We have Audio!
As a completely frivolous addition to the robot we wanted it to “talk”. By talk we mean issue Lemming sound effects! Previous jobs involved adding an amplifier to the pi. This challenge was to write some code that allowed a sound to be played from within Python.
It definitely sounds like the original!
import simpleaudio as sa import wave wave_read = wave.open(path_to_file, 'rb') audio_data = wave_read.readframes(wave_read.getnframes()) num_channels = wave_read.getnchannels() bytes_per_sample = wave_read.getsampwidth() sample_rate = wave_read.getframerate() play_obj = sa.play_buffer(audio_data, num_channels, bytes_per_sample, sample_rate) play_obj.wait_done()
To achieve this we used SimpleAudio from with python using something like this code. This was taken from the manual page of simpleaudio
One of the challenges was that the original lemming sound effects used some weird sample frequencies which are not supported by the pi. After playing them and comparing with the following list the closest approximation was used and hardcoded for that sample.