Electret condenser microphone
Electret condenser microphone
50 Hz to 15 kHz
4.5mV/Pa
2.2k
Signal-to-Noise Ratio (SNR) | 60 dB |
Compatible with Raspberry Pi OS and other Linux-based operating systems
30mm x 10mm x 10mm (L x W x H)
approximately 10 grams
Package Includes
1 x USB Microphone for Raspberry Pi
1 x USB cable (1.5m)
Color Variation
Please note that the color of the microphone may vary, but the functionality and features remain the same.
USB Microphone for Raspberry Pi (Color may Vary)
Overview
The USB Microphone for Raspberry Pi is a plug-and-play audio input device designed specifically for use with Raspberry Pi boards. This compact microphone connects directly to the Raspberry Pi's USB port, providing a convenient and easy-to-use solution for a wide range of audio applications.
Technical Specifications
Interface: USB 2.0
Sampling Rate: 44.1 kHz, 48 kHz, 96 kHz
Bit Depth: 16-bit
Frequency Response: 20 Hz - 20 kHz
Sensitivity: -40 dB 3 dB
Connector: USB-A
Hardware Requirements
Raspberry Pi (any model)
USB port
Software Requirements
Raspbian (recommended)
Python 3.x (for code examples)
Code Examples
### Example 1: Basic Audio Recording using Python
This example demonstrates how to use the USB Microphone to record audio using Python and the `pyaudio` library.
Hardware
Raspberry Pi (any model)
USB Microphone for Raspberry Pi
USB port
Software
Raspbian (recommended)
Python 3.x
`pyaudio` library (install using `pip install pyaudio`)
Code
```python
import pyaudio
import wave
# Initialize PyAudio
p = pyaudio.PyAudio()
# Open the microphone stream
stream = p.open(format=pyaudio.paInt16,
channels=1,
rate=44100,
input=True,
frames_per_buffer=1024)
print("Recording...")
# Record audio for 5 seconds
frames = []
for i in range(0, int(44100 / 1024 5)):
data = stream.read(1024)
frames.append(data)
# Close the stream
stream.stop_stream()
stream.close()
p.terminate()
# Save the recorded audio to a WAV file
wf = wave.open("recorded_audio.wav", "wb")
wf.setnchannels(1)
wf.setsampwidth(2)
wf.setframerate(44100)
wf.writeframes(b"".join(frames))
wf.close()
print("Recording saved to recorded_audio.wav")
```
### Example 2: Real-time Audio Processing using OpenCV and Python
This example demonstrates how to use the USB Microphone to capture audio in real-time and process it using OpenCV and Python.
Hardware
Raspberry Pi (any model)
USB Microphone for Raspberry Pi
USB port
Webcam (optional)
Software
Raspbian (recommended)
Python 3.x
OpenCV (install using `pip install opencv-python`)
`pyaudio` library (install using `pip install pyaudio`)
Code
```python
import cv2
import pyaudio
import numpy as np
# Initialize OpenCV
cv2.namedWindow("Audio Waveform")
# Initialize PyAudio
p = pyaudio.PyAudio()
# Open the microphone stream
stream = p.open(format=pyaudio.paInt16,
channels=1,
rate=44100,
input=True,
frames_per_buffer=1024)
while True:
# Read audio data from the microphone
data = stream.read(1024)
# Convert audio data to a NumPy array
audio_array = np.frombuffer(data, dtype=np.int16)
# Create a waveform image using OpenCV
img = np.zeros((200, 400, 3), dtype=np.uint8)
for i in range(len(audio_array)):
x = int(i 400 / len(audio_array))
y = int(100 + audio_array[i] / 32768 100)
cv2.line(img, (x, 100), (x, y), (0, 255, 0), 1)
# Display the waveform image
cv2.imshow("Audio Waveform", img)
# Exit on key press
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Close the stream and PyAudio
stream.stop_stream()
stream.close()
p.terminate()
cv2.destroyAllWindows()
```
Note: This example assumes a webcam is connected and available. If no webcam is present, the code will still run, but the waveform will not be displayed.