-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatvoice.py
92 lines (78 loc) · 2.85 KB
/
chatvoice.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# GPL 3.0
# User module for ahorrin chatbot
# Eduardo Contreras Chavez - Francisco Ruben Frias Valderrama
# Verano de investigacion AMC 2018 - Delfin 2018
# IIMAS-UNAM Dr. Ivan Vladimir Meza Ruiz
# imports
import argparse
import sys
import os.path
# local imports
import conversation
from audio import audio_connect, audio_close, audio_devices, set_audio_dirname
if __name__ == '__main__':
p = argparse.ArgumentParser("chatvoice")
p.add_argument("CONV",
help="Conversation file")
p.add_argument("--list_devices",
action="store_true", dest="list_devices",
help="List audio devices")
p.add_argument("--rec_voice",
action="store_true", dest="rec_voice",
help="Activate voice recognition")
p.add_argument("--audio_dir",default="rec_voice_audios",
action="store", dest="audio_dir",
help="Directory for audios for speech recognition")
p.add_argument("--google_tts",
action="store_true", dest="google_tts",
help="Use google tts")
p.add_argument("--local_tts",
action="store_true", dest="local_tts",
help="Use espeak local tts")
p.add_argument("--samplerate",type=int,default=16000,
action="store", dest="samplerate",
help="Samplerate")
p.add_argument("--channels",type=int,default=2,
action="store", dest="channels",
help="Number of channels microphone (1|2|...)")
p.add_argument("--device",type=int,default=None,
action="store", dest="device",
help="Device number to connect audio")
p.add_argument("--aggressiveness",type=int,default=None,
action="store", dest="aggressiveness",
help="VAD aggressiveness")
p.add_argument("-v", "--verbose",
action="store_true", dest="verbose",
help="Verbose mode [Off]")
args = p.parse_args()
if args.list_devices:
for info in audio_devices():
print(info)
sys.exit()
if args.google_tts:
tts="google"
elif args.local_tts:
tts="local"
else:
tts=None
# speech
if not os.path.exists(os.path.join(os.getcwd(), args.audio_dir)):
os.mkdir(os.path.join(os.getcwd(), args.audio_dir))
set_audio_dirname(args.audio_dir)
if args.aggressiveness:
vad_aggressiveness(args.aggressiveness)
#audio_connect(samplerate=args.samplerate,device=args.device,activate=args.rec_voice, channels=args.channels)
conversation = conversation.Conversation(
filename=args.CONV,
verbose=args.verbose,
tts=tts,
rec_voice=args.rec_voice,
channels=args.channels
)
conversation.execute()
print("Summary values:")
for val,k in conversation.slots.items():
print(val,k)