With Python APIs, you can connect CyberPi to the Internet and enable it to implement some AI functions, such as recognizing the languages of speeches and reading texts out loud.
In addition, you can use the text-to-speech (TTS) function of CyberPi in combination with the chatbot program of mkckoud to improve the intelligent level of CyberPi in voice chats.
Speech recognition
# Speech recognitionfrom time import sleepimport cyberpi# Note: This interface is not available for the Upload mode. It can be used only in Live mode.# To use the speech recognition function, you need to set a URL address:cyberpi.speech.set_recognition_address(url = "http://msapi.mblock.cc/ms/bing_speech/interactive")cyberpi.cloud.setkey("34d54aef8ede48379c5bf22c19aea159")# This part will be automatically configured in the future.cyberpi.wifi.connect("iPhone fftust", "12345678")# Set the account and password to those of the Wi-Fi you can connect towhile not cyberpi.wifi.is_connect():passcyberpi.console.clear()cyberpi.led.on(100, 0, 0)cyberpi.cloud.listen("english", 2)cyberpi.console.print(cyberpi.cloud.listen_result())cyberpi.led.on(0, 0, 0)
TTS
# TTSfrom time import sleepimport cyberpi# Set the urlcyberpi._cloud_tts.TTS_URL = "http://msapi.mblock.cc/baidu/voice/text2audio"cyberpi.cloud.setkey("34d54aef8ede48379c5bf22c19aea159")# setkey() is used to verify that you have the permission to use the Makeblock cloud servicecyberpi.wifi.connect("iPhone fftust", "12345678")# Set the account and password to those of the Wi-Fi you can connect tocyberpi.led.on(0, 0, 0)while not cyberpi.wifi.is_connect():passcyberpi.led.on(100, 0, 0)cyberpi.cloud.tts("english", "hello")
Chinese-English translation (more languages will be supported)
from time import sleepimport cyberpi# cyberpi.driver.cloud_translate.TRANS_URL = "http://msapi.mblock.cc/ms/bing_speech/translate"cyberpi.cloud.setkey("34d54aef8ede48379c5bf22c19aea159")cyberpi.wifi.connect("iPhone fftust", "12345678")# Set the account and password to those of the Wi-Fi you can connect tocyberpi.led.on(0, 0, 0)while not cyberpi.wifi.is_connect():passcyberpi.led.on(100, 0, 0)cyberpi.console.print(cyberpi.cloud.translate("english", "加油中国"))
