-
Notifications
You must be signed in to change notification settings - Fork 10
/
parse.py
62 lines (59 loc) · 2.23 KB
/
parse.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
import os
import datetime
import json
from soundMaker import GenerateSound
from chat import GenerateText
import logging
audio_path = './0.wav'
def update_audio():
global audio_path
return audio_path
class Parse:
role_name = ''
gt = None
store_path = ''
begin_time = ''
file_name = ''
cnt = 0
gs = None
# audio_path = './0.wav'
def __init__(self) -> None:
with open('./config.json', 'r', encoding='utf-8') as inform:
config = json.load(inform)
self.role_name = config["name"]
self.store_path = config["store-path"]
if not os.path.exists(self.store_path):
os.mkdir(self.store_path)
self.gt = GenerateText()
self.gs = GenerateSound()
date = datetime.datetime.now()
self.file_name = date.strftime('%Y-%m-%d-%H-%M-%S')
self.store_path = self.store_path + '/' + self.file_name
os.mkdir(self.store_path)
if not os.path.exists('./data/default.json'):
logging.error('default file not found')
exit(-1)
self.gt.uploadHistory('./data/default.json')
def loadHistory(self, history_file):
self.gt.uploadHistory(history_file.name)
logging.debug("load history successfully!!")
def logContent(self):
with open(self.store_path + './content.json', 'w', encoding='utf-8') as fs:
json.dump(self.gt.message_list, fs, ensure_ascii=False, indent=2)
def getText(self, text, max_length, top_p, temperature):
result = self.gt.getText(text, max_length, top_p, temperature)
if result == None:
exit()
return result
def switchAudio(self, text, ns, nsw, ls):
global audio_path
audio_path = self.store_path + '/' + str(self.cnt) + '.wav'
self.cnt += 1
self.gs.generateSound(text, audio_path, ns, nsw, ls)
logging.warning('text change to audio successfully!')
return text, audio_path
def PipeChat(self, text, max_length, top_p, temperature, ns, nsw, ls):
return self.switchAudio(self.getText(text, max_length, top_p, temperature), ns, nsw, ls)
if __name__ == '__main__':
ps = Parse()
ps.makeChat()