-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracy.py
123 lines (100 loc) · 4.19 KB
/
tracy.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
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
# tracy.py
# from stt import recognize_speech
# from intent_recognition import identify_intent
# from weather import get_weather
# from jokes_pro import get_joke_api
# from tts import speak_text_cli
# NEW: RAG imports
from rag_utils import (
load_and_chunk_squad_dataset,
build_vectorstore_from_contexts,
create_rag_chain,
get_rag_answer
)
# def main():
# # 1) Greet user
# speak_text("Hello! I'm Tracy, your voice assistant with RAG capabilities. How can I help you today?")
# # 2) Load some QA data (SQuAD) & build a RAG pipeline (this can be done once at startup)
# # contexts = load_and_chunk_squad_dataset()
# # vectorstore = build_vectorstore_from_contexts(contexts, "squad_collection")
# # rag_chain = create_rag_chain(vectorstore)
# # 3) Listen for user input
# user_input = recognize_speech() # from stt.py
# if user_input.lower() in ["exit", "quit", "bye"]:
# speak_text("Goodbye! Have a great day.")
# # 4) Identify intent
# intent = identify_intent(user_input) # from intent_recognition.py
# # 5) Route to correct function based on intent
# if intent == "weather":
# lat, lon = 40.7128, -74.0060 # Example: NYC coordinates
# weather_info = get_weather(lat, lon)
# speak_text(weather_info)
# elif intent == "joke":
# joke = get_joke_api()
# speak_text(joke)
# else:
# # If not recognized, try RAG QA
# speak_text("Let me check my knowledge base...")
# # 6) Use the RAG chain to answer user queries
# # answer = get_rag_answer(user_input, rag_chain)
# # speak_text(answer)
# tracy.py
# tracy.py
from stt import recognize_speech
from intent_recognition import identify_intent
from weather import get_weather
from jokes_pro import get_joke_api
# Import CLI-based function
from tts import speak_text_cli
def main():
# Suppose we place your absolute paths in one place:
model_cfg = "/Users/huy/Desktop/training/F5-TTS/src/f5_tts/configs/F5TTS_Base_train.yaml"
ckpt_file = "/Users/huy/Desktop/training/F5-TTS/ckpts/F5TTS_Base_vocos_custom_my_speak_custom/model_last.pt"
vocab_file = "/Users/huy/Desktop/training/F5-TTS/data/my_speak_custom_custom/vocab.txt"
speak_text_cli(
"Hello! I'm Tracy, your voice assistant. How can I help you today?",
model_name="F5-TTS",
model_cfg=model_cfg,
ckpt_file=ckpt_file,
vocab_file=vocab_file
)
user_input = recognize_speech()
if user_input.lower() in ["exit", "quit", "bye"]:
speak_text_cli("Goodbye!", model_cfg=model_cfg, ckpt_file=ckpt_file, vocab_file=vocab_file)
return
intent = identify_intent(user_input)
if intent == "weather":
info = get_weather(40.7128, -74.0060)
speak_text_cli(info, model_cfg=model_cfg, ckpt_file=ckpt_file, vocab_file=vocab_file)
elif intent == "joke":
speak_text_cli(get_joke_api(), model_cfg=model_cfg, ckpt_file=ckpt_file, vocab_file=vocab_file)
else:
speak_text_cli("Let me check my knowledge base...", model_cfg=model_cfg, ckpt_file=ckpt_file, vocab_file=vocab_file)
if __name__ == "__main__":
main()
# from stt import recognize_speech
# from intent_recognition import identify_intent
# from weather import get_weather
# from jokes_pro import get_joke_api
# from tts import MyDirectTTS
# def main():
# tts = MyDirectTTS(
# ckpt_file="/Users/huy/Desktop/training/F5-TTS/ckpts/F5TTS_Base_vocos_custom_my_speak_custom/model_last.pt",
# vocab_file="/Users/huy/Desktop/training/F5-TTS/data/my_speak_custom_custom/vocab.txt",
# device="cpu"
# )
# tts.speak_text_direct("Hello! I'm Tracy, your direct-load TTS. How can I help you?")
# user_input = recognize_speech()
# if user_input.lower() in ["exit", "quit", "bye"]:
# tts.speak_text_direct("Goodbye!")
# return
# intent = identify_intent(user_input)
# if intent == "weather":
# info = get_weather(40.7128, -74.0060)
# tts.speak_text_direct(info)
# elif intent == "joke":
# tts.speak_text_direct(get_joke_api())
# else:
# tts.speak_text_direct("Let me check my knowledge base...")
# if __name__ == "__main__":
# main()