-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathstartup_scripts.py
More file actions
153 lines (130 loc) · 7.81 KB
/
Copy pathstartup_scripts.py
File metadata and controls
153 lines (130 loc) · 7.81 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
from record_API import record_engine
from transcription_API import transcription_engine
from speach_API import speach_engine
from OBS_API import OBS_engine
from Youtube_API import youtube_engine
import winsound
import time
import os
import threading
from chat_API import neo_chat_engine
from Twitch_API import Bot
import utils
def main_chat_twitch_non_legacy(model, Vtuber_name, oauth_token, channal_name,banned_words, extend_profanity_list,HF_token):
chat_instance = neo_chat_engine(model,Vtuber_name,mem_length=5,token=HF_token,path_to_system_messages = "OpenVoice\system_message.txt", device_map="cuda",load_in_4bit=True,)
speach_instace = speach_engine()
twitch_instance = Bot(oauth_token,channal_name)# the Oauth_token can be found here: twitchapps.com/tmi and the chanal name is the name of the twitch chanal you want to read the chat from
bot_thread = threading.Thread(target=twitch_instance.run)
bot_thread.start()
print("connection complete!")
char_list = ['?', '!', '.', ':']
TTS_OUTPUT = "TTS_output.wav"
responded_messages = 0
chat_instance.send_to_conversation_memory("assistant",chat_instance.Vtuber_name,f"hello evryone I am {chat_instance.Vtuber_name}! welcome to my stream!")
while True:
#print("asdf")
chat_messages = twitch_instance.get_messages()
#print(chat_messages)
record_finish_time = time.time()
if len(chat_messages) > responded_messages and chat_messages != []:
most_recent_message = chat_messages[-1]
chat_instance.send_to_conversation_memory(most_recent_message['role'],most_recent_message['name'],most_recent_message['text'])
formated_input = chat_instance.format_input(chat_instance.chat_memory)
print("FORMATED INPUT",formated_input)
combined_string = ""
final_response = ""
TTS_finished_time = None
for new_text in chat_instance.generate(formated_input,max_new_tokens=400):
combined_string += new_text
final_response += new_text
#OBS_instance.update_text(combined_string)
if any(char in char_list for char in new_text):
TTS_text = combined_string
TTS_text = utils.censor(TTS_text, custom_badwords=banned_words,extend_profanity_list=extend_profanity_list)
combined_string = ""
speach_instace.TTS(TTS_text,TTS_OUTPUT)
if TTS_finished_time == None:
TTS_finished_time = time.time()
print("time to output:",TTS_finished_time - record_finish_time)
print("playimg")
winsound.PlaySound(TTS_OUTPUT,winsound.SND_FILENAME)
chat_instance.send_to_conversation_memory("assistant",chat_instance.Vtuber_name,final_response)
responded_messages +=1
#OBS_instance.update_text("")
def main_chat_youtube_non_legacy(model,Vtuber_name,banned_words,extend_profanity_list,HF_token):
chat_instance = neo_chat_engine(model,Vtuber_name,mem_length=5,token=HF_token,path_to_system_messages = "OpenVoice\system_message.txt",device_map="cuda",load_in_4bit=True,)
speach_instace = speach_engine()
youtube_instance = youtube_engine()
youtube_instance.message_compiler()
print("connection complete!")
char_list = ['?', '!', '.', ':']
TTS_OUTPUT = "TTS_output.wav"
responded_messages = 0
chat_instance.send_to_conversation_memory("assistant",chat_instance.Vtuber_name,f"hello evryone I am {chat_instance.Vtuber_name}! welcome to my stream!")
chat_instance.send_to_conversation_memory("user","henson","Hi! what is your favorite color?")
chat_instance.send_to_conversation_memory("assistant",chat_instance.Vtuber_name,"my favorite color is orange!")
while True:
chat_messages = youtube_instance.get_messages()
#print(chat_messages)
record_finish_time = time.time()
if len(chat_messages) > responded_messages and chat_messages != []:
most_recent_message = chat_messages[-1]
chat_instance.send_to_conversation_memory(most_recent_message['role'],most_recent_message['name'],most_recent_message['text'])
formated_input = chat_instance.format_input(chat_instance.chat_memory)
print("FORMATED INPUT",formated_input)
combined_string = ""
final_response = ""
TTS_finished_time = None
for new_text in chat_instance.generate(formated_input,max_new_tokens=400):
combined_string += new_text
final_response += new_text
#OBS_instance.update_text(combined_string)
if any(char in char_list for char in new_text):
TTS_text = combined_string
TTS_text = utils.censor(TTS_text,custom_badwords=banned_words,extend_profanity_list=extend_profanity_list)
combined_string = ""
speach_instace.TTS(TTS_text,TTS_OUTPUT)
if TTS_finished_time == None:
TTS_finished_time = time.time()
print("time to output:",TTS_finished_time - record_finish_time)
print("playimg")
winsound.PlaySound(TTS_OUTPUT,winsound.SND_FILENAME)
chat_instance.send_to_conversation_memory("assistant",chat_instance.Vtuber_name,final_response)
responded_messages +=1
#OBS_instance.update_text("")
def main_interview_non_legacy(model,Vtuber_name,your_name,banned_words,extend_profanity_list,HF_token):
chat_instance = neo_chat_engine(model,Vtuber_name,mem_length=3,token=HF_token,path_to_system_messages = "OpenVoice\system_message.txt",device_map="cuda",load_in_4bit=True,)
speach_instace = speach_engine()
record_instance = record_engine()
transcription_instance = transcription_engine()
OUTPUT_FILENAME="output.wav"
char_list = ['?', '!', '.', ':']
TTS_OUTPUT = "TTS_output.wav"
username = your_name
responded_messages = 0
chat_instance.send_to_conversation_memory("assistant",chat_instance.Vtuber_name,f"hello evryone I am {chat_instance.Vtuber_name}! welcome to my stream!")
while True:
output_file = record_instance.listener(OUTPUT_FILENAME)
record_finish_time = time.time()
transcribed_text = transcription_instance.whisper(output_file)
if transcribed_text != "":
chat_instance.send_to_conversation_memory("user",username,transcribed_text)
formated_input = chat_instance.format_input(chat_instance.chat_memory)
print("FORMATED INPUT",formated_input)
combined_string = ""
final_response = ""
TTS_finished_time = None
for new_text in chat_instance.generate(formated_input,max_new_tokens=400):
combined_string += new_text
final_response += new_text
if any(char in char_list for char in new_text):
TTS_text = combined_string
print("COMBINED STRING: ",combined_string)
f_TTS_text = utils.censor(TTS_text,custom_badwords=banned_words,extend_profanity_list=extend_profanity_list)
combined_string = ""
speach_instace.TTS(f_TTS_text,TTS_OUTPUT)
if TTS_finished_time == None:
TTS_finished_time = time.time()
print("time to output:",TTS_finished_time - record_finish_time)
winsound.PlaySound(TTS_OUTPUT,winsound.SND_FILENAME)
chat_instance.send_to_conversation_memory("assistant",chat_instance.Vtuber_name,final_response)