Audio Input and Output from USB Microphone + Raspberry Pi

From ESE205 Wiki
Revision as of 12:34, 7 December 2018 by Naraharip (talk | contribs)
Jump to: navigation, search

This tutorial will describe how to input audio to a Raspberry Pi using a USB microphone and furthermore how to output that audio simultaneously if needed.
Materials and Prerequisites

  • USB Microphone
  • Raspberry Pi

Install the following libraries:
PyAudio: Used to play and record audio on a variety of platforms. Install it by typing pip install pyaudio into the terminal
Numpy: fundamental package for scientific computing in Python. Install it by typing pip install numpy into the terminal

Copy the following Python script to read audio input to wave files:
Copy the following Python script for simultaneously streaming audio output with input:

import pyaudio
import numpy as np



#input stream setup = pyaudio.paInt16,rate=RATE,channels=1, input_device_index = 2, input=True, frames_per_buffer=chunk)

#output stream setup = pyaudio.paInt16,rate=RATE,channels=1, output=True, frames_per_buffer=chunk)

while True:            #Used to continuously stream audio
     data=np.fromstring(,exception_on_overflow = False),dtype=np.int16)
#closes streams

Pavan Narahari - Fall 2018
Sam Manyak - Fall 2018
Group Link
Crutooth References
The basis of the code was derived from the code developed by markjay4k, an engineer working with audio spectrum analyzers. You can find a link to his github at:
Here is the documentation for the PyAudio Library: PyAudio