simple program to record and turn into speech
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
""" product
|
||||
- (todo) keep recording in 5 second intervals
|
||||
simple algorithm. start recording, send to server after 5 seconds
|
||||
combine with currentTextBlock, and keep appending
|
||||
|
||||
process currentTextBlock every 5 seconds, and if fits command, then execute and clear currentTextBlock
|
||||
clear currentTextBlock after 200 characters as well
|
||||
|
||||
* show a light when sending to server for transcription
|
||||
|
||||
- hey rameelo, how long will I live?
|
||||
- good morning!
|
||||
"""
|
||||
|
||||
import time
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
import audio.audio as audio
|
||||
import tts.app as tts
|
||||
import requests
|
||||
from datetime import datetime
|
||||
import simple_recorder.apa102 as apa102
|
||||
|
||||
API_URL = "http://192.168.50.159:5001/transcribe"
|
||||
|
||||
BUTTON = 17
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(BUTTON, GPIO.IN)
|
||||
|
||||
audioInstance = audio.Audio()
|
||||
# number of pixels on the LED strip on the hat
|
||||
PIXELS_N = 3
|
||||
led = apa102.APA102(num_led=PIXELS_N)
|
||||
|
||||
|
||||
def turnOffLED():
|
||||
led.clear_strip()
|
||||
led.show()
|
||||
|
||||
|
||||
def turnOnLED():
|
||||
for i in range(PIXELS_N):
|
||||
led.set_pixel(i, 255, 192, 203)
|
||||
led.show()
|
||||
|
||||
|
||||
# see if we should execute a certain command based on the current text block
|
||||
def process(text):
|
||||
if "live" in text and "how long" in text:
|
||||
tts.say("")
|
||||
elif "good morning" in text:
|
||||
dt = datetime.now()
|
||||
dayOfWeek = dt.weekday()
|
||||
full_month_name = dt.strftime("%B")
|
||||
tts.say(f"Good morning! Today is {full_month_name} {dt.day}, {dt.year}. The day of the week is {dayOfWeek}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
while True:
|
||||
state = GPIO.input(BUTTON)
|
||||
|
||||
if state:
|
||||
if audioInstance.isRecording():
|
||||
turnOffLED()
|
||||
savedFileName = audioInstance.stopRecord(save=True, play=True)
|
||||
if savedFileName is not None:
|
||||
print("saved file: " + savedFileName)
|
||||
# make a request with the saved file to the api
|
||||
response = requests.request(
|
||||
"POST", API_URL, files={"file": open(savedFileName, "rb")}
|
||||
)
|
||||
print(response.json())
|
||||
results = response.json().get("results")
|
||||
command = results[0].transcript
|
||||
else:
|
||||
if not audioInstance.isRecording():
|
||||
turnOnLED()
|
||||
audioInstance.startRecord()
|
||||
@@ -1,49 +0,0 @@
|
||||
import time
|
||||
|
||||
import os
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
|
||||
BUTTON = 17
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(BUTTON, GPIO.IN)
|
||||
|
||||
|
||||
def robot(text):
|
||||
print("executing command")
|
||||
os.system("espeak -w output.wav \"" + text + "\"")
|
||||
os.system("aplay -D plughw:2,0 output.wav")
|
||||
|
||||
|
||||
def sayScript():
|
||||
print("initializing")
|
||||
robot("hey Heran?")
|
||||
robot("Based on your age, health, and habits, you have 10950 days left")
|
||||
robot("Make sure you chant more")
|
||||
time.sleep(5)
|
||||
|
||||
robot("hey Kam?")
|
||||
robot("you have some time, but make sure to surrender to jesus")
|
||||
time.sleep(5)
|
||||
|
||||
robot("hey Arjun")
|
||||
robot("You have maybe 12000 days left to live")
|
||||
robot("just drink some water or something")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
while True:
|
||||
try:
|
||||
state = GPIO.input(BUTTON)
|
||||
if state:
|
||||
print("off")
|
||||
else:
|
||||
print("on")
|
||||
sayScript()
|
||||
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
|
||||
time.sleep(1)
|
||||
Reference in New Issue
Block a user