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

  1. # Speech recognition
  2. from time import sleep
  3. import cyberpi
  4. # Note: This interface is not available for the Upload mode. It can be used only in Live mode.
  5. # To use the speech recognition function, you need to set a URL address:
  6. cyberpi.speech.set_recognition_address(url = "http://msapi.mblock.cc/ms/bing_speech/interactive")
  7. cyberpi.cloud.setkey("34d54aef8ede48379c5bf22c19aea159")
  8. # This part will be automatically configured in the future.
  9. cyberpi.wifi.connect("iPhone fftust", "12345678")
  10. # Set the account and password to those of the Wi-Fi you can connect to
  11. while not cyberpi.wifi.is_connect():
  12. pass
  13. cyberpi.console.clear()
  14. cyberpi.led.on(100, 0, 0)
  15. cyberpi.cloud.listen("english", 2)
  16. cyberpi.console.print(cyberpi.cloud.listen_result())
  17. cyberpi.led.on(0, 0, 0)

TTS

  1. # TTS
  2. from time import sleep
  3. import cyberpi
  4. # Set the url
  5. cyberpi._cloud_tts.TTS_URL = "http://msapi.mblock.cc/baidu/voice/text2audio"
  6. cyberpi.cloud.setkey("34d54aef8ede48379c5bf22c19aea159")
  7. # setkey() is used to verify that you have the permission to use the Makeblock cloud service
  8. cyberpi.wifi.connect("iPhone fftust", "12345678")
  9. # Set the account and password to those of the Wi-Fi you can connect to
  10. cyberpi.led.on(0, 0, 0)
  11. while not cyberpi.wifi.is_connect():
  12. pass
  13. cyberpi.led.on(100, 0, 0)
  14. cyberpi.cloud.tts("english", "hello")

Chinese-English translation (more languages will be supported)

  1. from time import sleep
  2. import cyberpi
  3. # cyberpi.driver.cloud_translate.TRANS_URL = "http://msapi.mblock.cc/ms/bing_speech/translate"
  4. cyberpi.cloud.setkey("34d54aef8ede48379c5bf22c19aea159")
  5. cyberpi.wifi.connect("iPhone fftust", "12345678")
  6. # Set the account and password to those of the Wi-Fi you can connect to
  7. cyberpi.led.on(0, 0, 0)
  8. while not cyberpi.wifi.is_connect():
  9. pass
  10. cyberpi.led.on(100, 0, 0)
  11. cyberpi.console.print(cyberpi.cloud.translate("english", "加油中国"))