-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
78 lines (62 loc) · 1.74 KB
/
bot.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
71
72
73
74
75
76
77
78
import logging
from voice_assistant_lib import (
init_voice_assistant,
listen,
play,
speech_to_text,
text_to_speech,
verify_wakeword,
chat,
register_function,
verify_voice,
)
CONFIG = {
'wakewords': ['carla', 'karla'],
'system_prompt': 'You are Carla, a voice assistant. Be friendly and concise.',
'pause_threshold': 1,
'dynamic_energy_threshold': False,
'energy_threshold': 4000,
}
init_voice_assistant(CONFIG)
def get_current_weather(location):
'''
Get the current weather
:param str location: The city and state, e.g. San Francisco, CA
'''
return {
"temperature_celcius": 20,
"weather": "sunny",
}
def get_secret():
'''
Get the secret passphrase.
The function will return the passphrase if it successfully authenticates the user.
If you are asked for the secret, always reauthenticate the user again with the get_secret function.
'''
instruction_audio = text_to_speech("Say 'Please authenticate me'", 'openai')
play(instruction_audio)
audio = listen()
verified = verify_voice(audio, 'voiceprint.wav')
if verified:
return {
'status': 'success',
'result': 'Down The Rabbit Hole',
}
else:
return {
'status': 'failed',
'error': 'Authentication failed',
}
register_function(get_current_weather)
register_function(get_secret)
while True:
audio_in = listen()
print(audio_in)
text_in = speech_to_text(audio_in, 'openai')
print(text_in)
if verify_wakeword(text_in):
text_out = chat(text_in)
print(text_out)
audio_out = text_to_speech(text_out, 'openai')
print(audio_out)
play(audio_out)