Creating a voice-activated digital voice recorder with a Raspberry Pi that accepts input from a wired 3.5 mm microphone, connects to a 4G network, and enables real-time monitoring and cloud uploading is an interesting project. Below is a parts list followed by a general set of instructions.
Parts List
-
Raspberry Pi:
- Raspberry Pi 3B/3B+ or Raspberry Pi 4 (with microSD card).
-
MicroSD Card:
- 16GB or higher (with Raspbian OS installed).
-
USB Sound Card:
- A USB sound card with a 3.5mm audio input (if the Raspberry Pi doesn't support the microphone directly).
-
Microphone:
- A wired 3.5mm microphone compatible with the USB sound card.
-
4G USB Modem:
- A compatible 4G USB modem with SIM card support (e.g., Huawei E3372, TP-Link MR3020).
-
Power Supply:
- A suitable power supply (5V, 2.5A).
-
USB OTG Cable:
- If needed, to connect the 4G modem.
-
Cables:
- Any additional cables you may need (e.g., audio cables, micro USB, etc.).
-
Cloud storage account:
- Choose one like Google Drive, Dropbox, or AWS S3 for cloud storage, and set up an account.
Instructions
1. Set up Raspberry Pi:
- Install the Raspbian OS on your microSD card and boot the Raspberry Pi.
- Connect the 4G modem and ensure it can access the internet.
2. Configure USB Sound Card and Microphone:
- Connect the USB sound card to the Raspberry Pi.
- Plug the wired microphone into the USB sound card.
3. Install Required Libraries and Software:
Open the terminal on your Raspberry Pi and run the following commands to get the necessary packages:
sudo apt-get update
sudo apt-get install sox libsox-fmt-all arecord
sudo apt-get install python3 python3-pip
pip3 install SpeechRecognition
sudo apt-get install python3-pyaudio
pip3 install requests # For uploading files to the cloud
4. Set up Voice Activation:
You can use the SpeechRecognition library for voice activation. Below is a simple example of how to record audio when a specific word is detected:
Create a Python script voice_recorder.py:
import pyaudio
import wave
import speech_recognition as sr
import time
import requests # For uploading
def record_audio(filename):
chunk = 1024
sample_format = pyaudio.paInt16
channels = 2
fs = 44100
seconds = 10
p = pyaudio.PyAudio()
stream = p.open(format=sample_format, channels=channels, rate=fs, frames_per_buffer=chunk)
frames = []
print('Recording...')
for i in range(0, int(fs / chunk * seconds)):
data = stream.read(chunk)
frames.append(data)
stream.stop_stream()
stream.close()
p.terminate()
with wave.open(filename, 'wb') as wf:
wf.setnchannels(channels)
wf.setsampwidth(p.get_sample_size(sample_format))
wf.setframerate(fs)
wf.writeframes(b''.join(frames))
print('Finished recording')
def upload_audio(filename):
url = 'YOUR_CLOUD_URL' # e.g., Google Drive, Dropbox, etc.
files = {'file': open(filename, 'rb')}
r = requests.post(url, files=files)
print(r.status_code)
def main():
r = sr.Recognizer()
while True:
with sr.Microphone() as source:
print("Listening...")
audio = r.listen(source)
try:
command = r.recognize_google(audio)
print("You said: " + command)
if "record" in command:
record_audio("recording.wav")
upload_audio("recording.wav")
except sr.UnknownValueError:
print("Could not understand audio")
except sr.RequestError:
print("Could not request results")
if __name__ == "__main__":
main()
5. Run the Script:
Save the script and run it using:
python3 voice_recorder.py
6. Testing:
Speak "record" into the microphone to activate the recording functionality.
Additional Resources:
You can look for Raspberry Pi and Python tutorials online for specific setups and configurations. Here are some useful links:
Make sure to adjust file upload functions according to the cloud service’s API you are using. Always test your setup to ensure everything works as intended.