何かを話す¶
このセクションでは、テキストを音声に変換して、Robot HATに大声で話させる方法を学びます。
手順
コマンドラインからテキストを取得してRobot HATがそれを話すようにします。これを実現するために、以下のコードを
.py
ファイルとして保存します。例えばtts.py
などです。import sys from robot_hat import TTS # Check if there are enough command line arguments if len(sys.argv) > 1: text_to_say = sys.argv[1] # Get the first argument passed from the command line else: text_to_say = "Hello SunFounder" # Default text if no arguments are provided # Initialize the TTS class tts = TTS(lang='en-US') # Read the text tts.say(text_to_say) # Display all supported languages print(tts.supported_lang())
Robot HATに特定の文章を発声させるには、次のコマンドを使用します:
sudo python3 tts.py "任意のテキスト"
- 単に"任意のテキスト"
を希望のフレーズに置き換えてください。