-
Notifications
You must be signed in to change notification settings - Fork 1
/
AudioTest.py
45 lines (34 loc) · 1.25 KB
/
AudioTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import RPi.GPIO as GPIO
import time
import json
import requests
from Transcript import determineTranscript
from Transcript import determineEmotion
from ToneAnalyzer import toneAnalyzer
import Keywords
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
os.system('aplay hello.wav')
while True:
mic_state = GPIO.input(23)
if (mic_state == False):
print('Recording')
os.system('arecord -D plughw:1,0 -d 5.0 speak.wav')
print ('Retrieving Transcript')
url = 'https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?model=en-US_NarrowbandModel&continuous=true&'
username = 'USERNAME'
password = 'PASSWORD'
headers = {"Content-Type": 'audio/wav'}
audio = open('speak.wav', 'rb')
r = requests.post(url=url, data=audio, headers=headers, auth=(username, password))
text_file = open("WatsonSTTResult.txt", "w")
text_file.write(r.text)
text_file.close()
transcript = determineTranscript()
if "bye" in transcript:
os.system('aplay bye.wav')
os.system('sudo poweroff')
if "false" not in transcript:
toneAnalyzer(transcript)
Keywords.ifAngrySad(determineEmotion())