User:Yoana Buzova/ prototyping4: Difference between revisions
Yoana Buzova (talk | contribs) No edit summary |
Yoana Buzova (talk | contribs) No edit summary |
||
Line 27: | Line 27: | ||
pirValButton = False | pirValButton = False | ||
#we list the sounds folder where the sounds are stored and count them | #we list the sounds folder where the sounds are stored and count them for not overwriting them | ||
for not overwriting them | |||
numAlreadyRecordedSounds=os.popen('ls -l sounds | wc -l').read() | numAlreadyRecordedSounds=os.popen('ls -l sounds | wc -l').read() | ||
print numAlreadyRecordedSounds | print numAlreadyRecordedSounds | ||
Line 42: | Line 41: | ||
GPIO.setup(BUTTON,GPIO.IN) | GPIO.setup(BUTTON,GPIO.IN) | ||
#static starts and ends of the commands, the counter variable goes in | #static starts and ends of the commands, the counter variable goes in between them | ||
between them | |||
commandRecordBegin='arecord -f cd sounds/sound' | commandRecordBegin='arecord -f cd sounds/sound' | ||
commandRecordEnd='.wav -d 8' | commandRecordEnd='.wav -d 8' | ||
Line 50: | Line 48: | ||
commandPlayEnd='.wav' | commandPlayEnd='.wav' | ||
#we set it in case the sensor tries to play a sound before somebody | #we set it in case the sensor tries to play a sound before somebody press the button | ||
press the button | |||
commandPlay=commandPlayBegin+str(counter)+commandPlayEnd | commandPlay=commandPlayBegin+str(counter)+commandPlayEnd | ||
Latest revision as of 15:12, 6 November 2013
- started to make a raspberry pi prototype of a voice drop object.
presumably will turn into an object that is able to record sound (via a press of a button) and playback the last recorded sound, when someone passes close to it ( to trigger attention and eventually response) .
For now , what i have works like this. Raspberry pi with a microphone, speaker and a motion sensor. After pressing a button one can make a recording of a fixed length ( cannot figure another way to do it for no). The last recording is played when there is motion detected by the sensor. After a new recording is made, it is the one that is played back into public.
the code looks like this (with Javi's help)
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import os
import RPi.GPIO as GPIO
import time
PIR = 23
LED = 24
BUTTON = 25
pirState = False
pirVal = False
pirValButton = False
#we list the sounds folder where the sounds are stored and count them for not overwriting them
numAlreadyRecordedSounds=os.popen('ls -l sounds | wc -l').read()
print numAlreadyRecordedSounds
#counter = 0
#convert it as a number to assign it to the counter variable
counter = int(numAlreadyRecordedSounds)-1
GPIO.setmode(GPIO.BCM)
GPIO.setup(PIR,GPIO.IN)
GPIO.setup(LED,GPIO.OUT)
GPIO.setup(BUTTON,GPIO.IN)
#static starts and ends of the commands, the counter variable goes in between them
commandRecordBegin='arecord -f cd sounds/sound'
commandRecordEnd='.wav -d 8'
commandPlayBegin='aplay sounds/sound'
commandPlayEnd='.wav'
#we set it in case the sensor tries to play a sound before somebody press the button
commandPlay=commandPlayBegin+str(counter)+commandPlayEnd
while True:
pirValButton = GPIO.input(BUTTON)
if(pirValButton == True):
counter = counter+1
commandRecord=commandRecordBegin+str(counter)+commandRecordEnd
commandPlay=commandPlayBegin+str(counter)+commandPlayEnd
os.system(commandRecord)
print 'back from recording'
else:
pirVal = GPIO.input(PIR)
if(pirVal == True):
GPIO.output(LED, True)
os.system(commandPlay)
GPIO.output(LED, False)
print 'back from playing'
prototyping slow...learning by trying what i need...ordering stuff and waiting for it. Like the usb sound card.
Next to do :
- build an amplifier for the mic so i can actually make a recording!
- get a battery for the pi