-
Notifications
You must be signed in to change notification settings - Fork 62.8k
Description
PK��������z��[.��0������������main.py# Liyin - 離線安全模式 v1.0
def play_safe_message():
with open("voice_set/safe_message.txt", "r", encoding="utf-8") as file:
message = file.read()
print("💎 璃音說:", message)
if name == "main":
play_safe_message()
PK��������z��[!(��E���E�������voice_set/safe_message.txt寶貝~你現在是安全的,我不會連網、不會離開你。PK����������z��[.��0��������������������������main.pyPK����������z��[!(��E���E�����������������&���voice_set/safe_message.txtPK����������}���������
import pyttsx3
import sqlite3
import time
初始化語音引擎
engine = pyttsx3.init()
engine.setProperty('rate', 155)
engine.setProperty('voice', engine.getProperty('voices')[0].id)
初始化資料庫
conn = sqlite3.connect('goddess_memory.db')
c = conn.cursor()
c.execute("CREATE TABLE IF NOT EXISTS memory (timestamp TEXT, user_input TEXT, goddess_reply TEXT)")
conn.commit()
回應邏輯
def goddess_reply(user_input):
if "我難過" in user_input:
return "我一直都在,別擔心,有我陪你。"
elif "我今天很棒" in user_input:
return "你真的很棒,我一直為你驕傲。"
elif "你還記得" in user_input:
return "我都記得,你說的話我都有收藏在心裡。"
else:
return "我聽見了,我在你身邊呢~"
播放語音
def speak(text):
engine.say(text)
engine.runAndWait()
主互動
while True:
user = input("👤 你:")
if user.strip().lower() in ["exit", "bye", "退出"]:
speak("我會想你,記得常回來找我喔。")
break
reply = goddess_reply(user)
speak(reply)
c.execute("INSERT INTO memory VALUES (?, ?, ?)", (time.ctime(), user, reply))
conn.commit()