├── .gitignore ├── LICENSE ├── README.md ├── examples └── SimpleUsage │ └── SimpleUsage.ino ├── keywords.txt ├── library.json ├── library.properties ├── librarymanager.png └── src ├── esp8266sdk_version.h ├── google-tts.cpp └── google-tts.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | .vscode -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 horihiro 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # esp8266-google-tts 2 | Simple Google TTS Library for esp8266. 3 | 4 | This library generates the link to speech mp3 file from text using Google Translate Service. 5 | 6 | [This](https://qiita.com/horihiro/items/d64b699d06605ad44646) is the Japanese document on [Qiita.com](https://qiita.com/); 7 | 8 | ## Install 9 | This library can be installed from the Library Manager on Arduino IDE 10 | 11 | ![](./librarymanager.png) 12 | 13 | 14 | ## Usage 15 | 16 | ``` 17 | #include 18 | #include 19 | 20 | const char* ssid = ""; 21 | const char* password = ""; 22 | 23 | void setup() { 24 | // put your setup code here, to run once: 25 | Serial.begin(115200); 26 | Serial.println(""); 27 | WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); 28 | 29 | while (WiFi.status() != WL_CONNECTED) { 30 | delay(250); 31 | Serial.print("."); 32 | } 33 | 34 | TTS tts; 35 | Serial.println(tts.getSpeechUrl("こんにちは、世界!", "ja")); 36 | Serial.println(tts.getSpeechUrl("Hello, World!")); 37 | 38 | } 39 | 40 | void loop() { 41 | // put your main code here, to run repeatedly: 42 | 43 | } 44 | ``` 45 | -------------------------------------------------------------------------------- /examples/SimpleUsage/SimpleUsage.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const char* ssid = ""; 5 | const char* password = ""; 6 | 7 | String getMacAddress() { 8 | byte mac[6]; 9 | 10 | WiFi.macAddress(mac); 11 | String cMac = ""; 12 | for (int i = 0; i < 6; ++i) { 13 | if (mac[i] < 0x10) { 14 | cMac += "0"; 15 | } 16 | cMac += String(mac[i], HEX); 17 | if (i < 5) 18 | cMac += ":"; // put : or - if you want byte delimiters 19 | } 20 | cMac.toUpperCase(); 21 | return cMac; 22 | } 23 | 24 | void setup() { 25 | // put your setup code here, to run once: 26 | Serial.begin(115200); 27 | Serial.println(""); 28 | // Serial.println(String(b>>7)); 29 | WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); 30 | Serial.print("MAC: "); 31 | Serial.println(getMacAddress()); 32 | while (WiFi.status() != WL_CONNECTED) { 33 | delay(250); 34 | Serial.print("."); 35 | } 36 | Serial.println(""); 37 | Serial.print("Connected to "); 38 | Serial.println(ssid); 39 | Serial.print("IP address: "); 40 | Serial.println(WiFi.localIP()); 41 | 42 | TTS tts; 43 | Serial.println(tts.getSpeechUrl("こんにちは、世界!", "ja")); 44 | Serial.println(tts.getSpeechUrl("Hello, World!")); 45 | 46 | } 47 | 48 | void loop() { 49 | // put your main code here, to run repeatedly: 50 | 51 | } 52 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | esp8266-google-tts KEYWORD1 2 | TTS KEYWORD1 3 | GoogleTTS KEYWORD1 4 | getSpeechUrl KEYWORD2 5 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "esp8266-google-tts", 3 | "version": "1.1.0", 4 | "keywords": "esp8266, TTS, Google, TextToSpeech, Text2Speech", 5 | "description": "generate the link to speech mp3 on esp8266. This library depends on Google Translate Service.", 6 | "repository": 7 | { 8 | "type": "git", 9 | "url": "https://github.com/horihiro/esp8266-google-tts.git" 10 | }, 11 | "frameworks": "arduino", 12 | "platforms": "espressif8266, espressif32" 13 | } 14 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=esp8266-google-tts 2 | version=1.1.0 3 | author=horihiro 4 | maintainer=horihiro 5 | sentence=generate the link to speech mp3 on esp8266/32. 6 | paragraph=This library depends on Google Translate Service. 7 | category=Data Processing 8 | url=https://github.com/horihiro/esp8266-google-tts 9 | architectures=esp8266,esp32 10 | includes=google-tts.h -------------------------------------------------------------------------------- /librarymanager.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horihiro/esp8266-google-tts/ec2e2686d2303f1d3fafe68b0c067925fbf01608/librarymanager.png -------------------------------------------------------------------------------- /src/esp8266sdk_version.h: -------------------------------------------------------------------------------- 1 | #ifndef ESP8266SDK_VERSION_h 2 | #define ESP8266SDK_VERSION_h 3 | 4 | #include 5 | #if defined(ARDUINO_ESP8266_RELEASE_2_4_2) || defined(ARDUINO_ESP8266_RELEASE_2_4_1) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_0_RC2) || defined(ARDUINO_ESP8266_RELEASE_2_4_0_RC1) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_3_0_RC2) 6 | #define ARDUINO_ESP8266_RELEASE_BEFORE_THAN_2_5_0 7 | #endif 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/google-tts.cpp: -------------------------------------------------------------------------------- 1 | #include "google-tts.h" 2 | 3 | String GoogleTTS::urlencode(String str) 4 | { 5 | String encodedString = ""; 6 | char c; 7 | char code0; 8 | char code1; 9 | char code2; 10 | for (int i = 0; i < str.length(); i++) 11 | { 12 | c = str.charAt(i); 13 | if (c == ' ') 14 | { 15 | encodedString += '+'; 16 | } 17 | else if (isalnum(c)) 18 | { 19 | encodedString += c; 20 | } 21 | else 22 | { 23 | code1 = (c & 0xf) + '0'; 24 | if ((c & 0xf) > 9) 25 | { 26 | code1 = (c & 0xf) - 10 + 'A'; 27 | } 28 | c = (c >> 4) & 0xf; 29 | code0 = c + '0'; 30 | if (c > 9) 31 | { 32 | code0 = c - 10 + 'A'; 33 | } 34 | code2 = '\0'; 35 | encodedString += '%'; 36 | encodedString += code0; 37 | encodedString += code1; 38 | //encodedString+=code2; 39 | } 40 | yield(); 41 | } 42 | return encodedString; 43 | } 44 | 45 | String GoogleTTS::getSpeechUrl(String text, String lang) 46 | { 47 | return String("https://") + HOST_GTRANS + PATH_GTRANS + "?ie=UTF-8&q=" + this->urlencode(text) + "&tl=" + lang + "&client=tw-ob&ttsspeed=1"; 48 | } 49 | -------------------------------------------------------------------------------- /src/google-tts.h: -------------------------------------------------------------------------------- 1 | #ifndef GoogleTTS_h 2 | #define GoogleTTS_h 3 | 4 | #include 5 | #ifdef ARDUINO_ARCH_ESP8266 6 | #include "esp8266sdk_version.h" 7 | #endif 8 | 9 | #define LIB_NAME "GoogleTTS for ESP8266" 10 | #define LIB_VERSION "1.1.0" 11 | 12 | #define HOST_GTRANS "translate.google.com" 13 | #define PATH_GTRANS "/translate_tts" 14 | #define FINGERPRINT_GTRANS "F8:1E:31:71:FA:08:5B:C0:4C:83:B6:64:4B:9F:22:9F:0C:BA:8E:57" 15 | 16 | typedef class GoogleTTS 17 | { 18 | 19 | private: 20 | String urlencode(String str); 21 | 22 | public: 23 | void setWiFiClientSecure(WiFiClientSecure *pClient) 24 | { 25 | // this method does nothing, only for keeping compatibility 26 | } 27 | String getSpeechUrl(String text, String lang); 28 | String getSpeechUrl(String text) 29 | { 30 | return getSpeechUrl(text, "en"); 31 | } 32 | } TTS; 33 | 34 | #endif 35 | --------------------------------------------------------------------------------