Voice Control 簡單示範 - 控制風扇

這次活動將會利用 Voice Control 發出 command 來控制風扇(motor)的開關 ,

當接收到「fan」的語音輸入時 , 風扇(motor)便會開啟 ;

當接收到「stop」的語音輸入時 , 便會關閉。

所需材料 :

TXT 4.0 Controller x 1

Motor XS x 1

紅綠電線 x 1

風扇組件 x 1

iPad x 1 ( Voice Control App + Robo Pro Coding)

電線接駁方法 :

Motor > O1 O2 (M1)

Controller Configuration :

選取 TXT 4.0 Controller

在 「Motor」選取「Motor」

將它擺放到「Motor」的位置 , 擺入後會出現「M1」 (代按M1 port)

選擇 Learning level :

在編程欄的最上能看到「Learning level」 , 為了能用到 Voice Control 的 coding block

需要更改成 level 3 (Expert) , 點擊「Learning level」再選擇 Expert 即可

編程教學 :

從 「Voice Control」取出「on command received : text」

在「Display」中取出「set label ... text to」

將「set label....」放入「received text」 , 讓 Controller 能顯示文字

從 「Voice Control」取出「 text」

把「text」放至「set label ....」後 , 目的是當 TXT 4.0 Controller 收到語音指令時會在螢幕上顯示出跟指令一樣的文字

打開 「logic」取出「if do」 及 「=」, 「if do」的功能是替我們接收 command (if) 及控制 motor (do) , 「=」則用作檢測

將 「if do」放至 「print text」的下面 , 再按「+」新增出「else if」 , 從而讓我們可以檢測到 2 個 command

這裡介紹一個常用的功能 「Duplicate」 , 右 click 需複製的 coding block 然後按 「Duplicate」便可複製 ,

複製後將「text」放至「=」的前方空格

在「text」取出這個 text command 來輸入文字

將 text command 放至 = 的後面來輸入文字

寫成 if text = fan , else if text = stop 來檢測這2個 voice command , 「fan」跟「stop」將會是你的語音輸入詞

最後到「Motor」取出「set motor ccw speed 512」及「stop motor」

分別放至 「text = fan」 及 「text = stop」 後

CCW 的意思是順時針轉動無需改動 , 512 為最快的轉速可自行改變數值 ; 數值為 0 - 512

編程總覽 :

Voice Control 教學 :

按下 「MIC」進入說話頁面

出現 「Speak now」時講話 , App 便會依據你說出的內容生成 command

你將會在 workspace 上看到你說過的文字內容 , 假如該文字跟 TXT Controller 的 command一樣便會執行編程內容

影片示範 :