-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
71 lines (60 loc) · 2.4 KB
/
main.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
import os
from functions.keys.api_key_chat import API_KEY_OPENAI
from functions.tts import text_to_speech, PlayVoice
from functions.chatbot import chatGPT
from functions.create_subtitle import subtitle
# Change your character name here
name = "kana"
directory_path = os.path.dirname(os.path.realpath(__file__))
gpt_key = API_KEY_OPENAI
first_time_run = True
previous_chat = ""
# File names
answer_file = (directory_path + r"\answer.txt")
answer_en_file = (directory_path + r"\answerEN.txt")
answer_jp_file = (directory_path + r"\answerJP.txt")
newest_chat_file = (directory_path + r"\NewestChat.txt")
subtitle_file = (directory_path + r"\subtitle.txt")
history_file = (directory_path + r"\ChatHistory.txt")
prompt_file = (directory_path + r"\RoleAndStory.txt")
def clear_files(newest_chat_file, subtitle_file, history_file):
with open(newest_chat_file, "w") as file:
file.write("the stream just start! introduce yourself")
open(subtitle_file, "w").close()
with open(history_file, "w") as file:
file.write("*this is your chat log*")
# Code to check if the Voicevox engine is already open otherwise code will error
text = "操作する準備ができています"
with open(answer_jp_file, "w", encoding="utf-8") as file:
file.write(text)
text_to_speech(answer_jp_file)
PlayVoice()
clear_files(newest_chat_file, subtitle_file, history_file)
while True:
with open(newest_chat_file, "r", encoding="utf-8") as file:
current_chat = file.read()
# Check if the chat being read is the same as the previous chat
if current_chat != previous_chat:
response = chatGPT(
gpt_key,
file_path_prompt,
file_path_newest,
file_path_history,
file_path_answer,
file_path_answer_jp,
file_path_answer_en,
name,
)
text_to_speech(file_path_answer_jp)
previous_chat = current_chat
with open(answer_en_file, "r", encoding="utf-8") as final_answer_file:
text = final_answer_file.read()
subtitle(text)
PlayVoice()
with open(history_file, "r", encoding="utf-8") as file:
file_contents = file.read()
# Calculate the number of characters in chat log
character_count = len(file_contents)
if character_count > 3000:
with open(history_file, "w") as file:
file.write("*this is your chat log*")