-
Notifications
You must be signed in to change notification settings - Fork 0
/
VRtest.py
70 lines (56 loc) · 1.82 KB
/
VRtest.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import speech_recognition as sr
from textblob import TextBlob
from playsound import playsound
from gtts import gTTS
import argparse
from google.cloud import language
from google.cloud.language import enums
from google.cloud.language import types
GOOGLE_CLOUD_SPEECH_CREDENTIALS =
counter = 0
def speaker(toTalk):
tts = gTTS(toTalk)
tts.save('speaking' + str(counter) + '.mp3')
playsound('speaking' + str(counter) + '.mp3')
# speaker("Hello world.")
# counter+=1
# speaker("My name is hal9000")
# counter+=1
# speaker("I am here to listen")
# counter+=1
# speaker("Tell me about your feelings ")
# counter+=1
# obtain audio from the microphone
def listener():
r = sr.Recognizer()
with sr.Microphone() as source:
print("listening")
audio = r.listen(source)
try:
print("speech detected")
speech = r.recognize_google_cloud(audio, credentials_json=GOOGLE_CLOUD_SPEECH_CREDENTIALS)
return speech
except sr.UnknownValueError:
print("Google Cloud Speech could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Cloud Speech service; {0}".format(e))
speech = listener()
print("You said: " + speech)
content = speech
client = language.LanguageServiceClient()
document = types.Document(
content=content,
type=enums.Document.Type.PLAIN_TEXT)
annotations = client.analyze_sentiment(document=document)
magnitude = annotations.document_sentiment.magnitude
print(magnitude)
# blob = TextBlob(speech)
# for sentence in blob.sentences:
# print(sentence.sentiment.polarity)
# happyness = sentence.sentiment.polarity
# if happyness > 0:
# counter +=1
# speaker("Seems like your day has been pretty good! Keep it up!")
# else:
# counter +=2
# speaker("Cheer up, its not too bad. There's always tomorrow!")