LoginSignup
8
7

More than 5 years have passed since last update.

Google 翻訳を使って、ESP8266 で TextToSpeech するライブラリ

Last updated at Posted at 2018-04-15

実際には、ESP8266 は喋らないので、タイトル詐欺です。

できること

繰り返しますが、ESP8266 は一言も喋りません。
Google 翻訳を使って、喋らせたいテキストから、音声ファイル (mp3) の URL を作るだけです。
作った URL から音声ファイルのダウンロードもしません。

要は、node.js 用モジュールの google-tts-api の再発明です。

音声ファイルのダウンロードや再生は、各自で実装いただければ。

インストール

やってみたかったので、Arduino IDE のライブラリ マネージャーに登録してみました。
ここに書かれたとおりに必要なファイル (library.properties とか) を作り、こんな感じArduino の公式リポジトリで issue を登録すると、翌日くらいにサクっと登録されます。

こんな簡単に公開できて、品質は全く問われないのは、ある意味怖いですね。

ライブラリ マネージャのおかげで、インストールは楽ちんです。
image.png

使い方

#include <google-tts.h>
#include <ESP8266WiFi.h>

const char* ssid     = "<REPLASE_YOUR_WIFI_SSID>";
const char* password = "<REPLASE_YOUR_WIFI_PASSWORD>";

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(250);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  TTS tts;
  Serial.println(tts.getSpeechUrl("こんにちは、世界!", "ja"));
  Serial.println(tts.getSpeechUrl("Hello, World!"));

}

void loop() {
  // put your main code here, to run repeatedly:

}

メソッドは、getSpeechUrl のみで、第一引数に音声にしたいテキスト、第二引数に言語情報を入れるだけです。日本語の場合、ja を指定してください。
第二引数を省略すると、en (英語) として実行します。

今後

これが何に使えるか考えてます。

8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7