1
1
import sim
2
- from usr .ui import SelectWindow , ChatWindow
3
2
from usr .jobs import scheduler
4
3
from usr import pypubsub as pub
5
4
@@ -33,59 +32,28 @@ def ai_callback(args):
33
32
global GPIO39
34
33
event = args [0 ]
35
34
msg = args [1 ]
36
- global chat_win
37
35
if event == 1 :
38
36
print ('TIKTOK_RTC_EVENT_START' )
39
37
GPIO39 .write (1 )
40
- chat_win .update_status ("Please speak to me" )
41
38
elif event == 2 :
42
39
print ('TIKTOK_RTC_EVENT_STOP' )
43
40
GPIO39 .write (0 )
44
41
elif event == 3 :
45
- #chat_win.update_status("AI speaking . . .")
46
42
print ('TIKTOK_RTC_EVENT_TTS_TEXT {}' .format (msg ))
47
43
#call.stopAudioService()
48
44
elif event == 4 :
49
- #chat_win.update_status("AI listening . . .")
50
45
print ('TIKTOK_RTC_EVENT_ASR_TEXT {}' .format (msg ))
51
46
#call.stopAudioService()
52
47
elif event == 5 :
53
48
print ('TIKTOK_RTC_EVENT_ERROR {}' .format (msg ))
54
49
else :
55
50
print ('TIKTOK_RTC_EVENT UNKNOWN {}' .format (event ))
56
51
57
- def update_status_with_animation (chat_win , base_message , steps = 3 , delay_ms = 400 , final_wait = 2 ):
58
- # 更新动画
59
- for i in range (steps + 1 ):
60
- chat_win .update_status (base_message + " " + " ." * i )
61
- time .sleep_ms (delay_ms )
62
- time .sleep (final_wait )
63
-
64
- def perform_initialization (chat_win , tiktok ):
65
- # 初始化动画加载状态
66
- print ('start rtc' )
67
- chat_win .show ()
68
- tiktok .active (True )
69
-
70
- # 需要展示的状态列表
71
- status_list = [
72
- "Connecting to the server" ,
73
- "Building the AI engine" ,
74
- "Joining the AI room" ,
75
- "Loading AI personality" ,
76
- "Creating AI characters"
77
- ]
78
-
79
- # 依次遍历状态并显示动画
80
- for status in status_list :
81
- update_status_with_animation (chat_win , status )
82
52
def ai_task ():
83
53
global rtc_queue
84
54
global extint1
85
55
global extint2
86
56
global tiktok
87
- global chat_win
88
- global selsct_win
89
57
while True :
90
58
lte = dataCall .getInfo (1 , 0 )
91
59
if lte [2 ][0 ] == 1 :
@@ -99,16 +67,16 @@ def ai_task():
99
67
extint1 .enable ()
100
68
extint2 .enable ()
101
69
print ('ai task running' )
70
+
102
71
while True :
103
72
data = rtc_queue .get ()
104
73
print ('rtc_queue key event {}' .format (data ))
105
74
if data == 1 :
106
- perform_initialization (chat_win , tiktok )
75
+ print ('start rtc' )
76
+ tiktok .active (True )
107
77
elif data == 2 :
108
78
print ('stop rtc' )
109
- selsct_win .show ()
110
79
tiktok .active (False )
111
-
112
80
113
81
if __name__ == "__main__" :
114
82
@@ -118,16 +86,10 @@ def ai_task():
118
86
sim .setSimDet (1 , 1 )
119
87
120
88
# 设置按键中断
121
- extint1 = ExtInt (ExtInt .GPIO13 , ExtInt .IRQ_FALLING , ExtInt .PULL_PU , key1 , filter_time = 50 )
122
- extint2 = ExtInt (ExtInt .GPIO12 , ExtInt .IRQ_FALLING , ExtInt .PULL_PU , key2 , filter_time = 50 )
89
+ extint1 = ExtInt (ExtInt .GPIO45 , ExtInt .IRQ_FALLING , ExtInt .PULL_PU , key1 , filter_time = 50 )
90
+ extint2 = ExtInt (ExtInt .GPIO46 , ExtInt .IRQ_FALLING , ExtInt .PULL_PU , key2 , filter_time = 50 )
123
91
124
92
rtc_queue = Queue ()
125
-
126
- # 初始化界面
127
- selsct_win = SelectWindow ()
128
- selsct_win .show ()
129
-
130
- chat_win = ChatWindow ()
131
93
132
94
# 启动后台任务调度器
133
95
scheduler .start ()
@@ -136,7 +98,7 @@ def ai_task():
136
98
137
99
tiktok = TiktokRTC (300000 , ai_callback )
138
100
GPIO39 = Pin (PA , Pin .OUT , Pin .PULL_DISABLE , 0 )
139
- tiktok .config (volume = 6 )
101
+ tiktok .config (volume = 11 )
140
102
print ('volume: {}' .format (tiktok .config ('volume' )))
141
103
142
104
_thread .start_new_thread (ai_task , ())
0 commit comments