Difference between revisions of "Audio Input and Output from USB Microphone + Raspberry Pi"

From ESE205 Wiki
Jump to: navigation, search
Line 1: Line 1:
'''Overview''' <br/>
+
== Overview ==
 
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.  
 
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.  
 
<br/>
 
<br/>
'''Materials and Prerequisites'''<br/>
+
== Materials and Prerequisites ==
 
*USB Microphone
 
*USB Microphone
 
*Raspberry Pi
 
*Raspberry Pi
'''Process'''
+
== Process ==
<br/>
+
'''Libraries to Install'''
Install the following libraries:
 
 
<br/>
 
<br/>
 
PyAudio: Used to play and record audio on a variety of platforms. Install it by typing
 
PyAudio: Used to play and record audio on a variety of platforms. Install it by typing
Line 16: Line 15:
 
<br/>
 
<br/>
  
 +
'''Code''' <br/>
 
Copy the following Python script to read audio input to wave files:
 
Copy the following Python script to read audio input to wave files:
 
<br/>
 
<br/>
Line 45: Line 45:
 
</source>
 
</source>
  
'''Authors''' <br/>
+
== Authors ==
 
Pavan Narahari - Fall 2018 <br/>
 
Pavan Narahari - Fall 2018 <br/>
 
Sam Manyak - Fall 2018
 
Sam Manyak - Fall 2018
 
<br/>
 
<br/>
'''Group Link'''<br/>
+
== Group Link ==
 
[https://classes.engineering.wustl.edu/ese205/core/index.php?title=Crutooth Crutooth]
 
[https://classes.engineering.wustl.edu/ese205/core/index.php?title=Crutooth Crutooth]
 
<br/>
 
<br/>
'''References'''<br/>
+
== 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: https://github.com/markjay4k/Audio-Spectrum-Analyzer-in-Python
 
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: https://github.com/markjay4k/Audio-Spectrum-Analyzer-in-Python
 
<br/>
 
<br/>

Revision as of 12:50, 7 December 2018

Overview

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

Process

Libraries to Install
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

Code
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

chunk=4096
RATE=44100

p=pyaudio.PyAudio()

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

#output stream setup
player=p.open(format = pyaudio.paInt16,rate=RATE,channels=1, output=True, frames_per_buffer=chunk)

while True:            #Used to continuously stream audio
     data=np.fromstring(stream.read(chunk,exception_on_overflow = False),dtype=np.int16)
     player.write(data,chunk)
    
#closes streams
stream.stop_stream()
stream.close()
p.terminate

Authors

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: https://github.com/markjay4k/Audio-Spectrum-Analyzer-in-Python
Here is the documentation for the PyAudio Library: PyAudio