So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By GalactusX31
#92808 First of all, hello everyone from a newbie;)

Second, I've been trying for a while to develop an application, using the google-tts https://github.com/horihiro/esp8266-google-tts library, that can download the embedded audios in the generated google translator links, but I don't have a sufficient level of knowledge to make this possible.

My intention is to create a talking clock (for my sister who is blind), and by pressing a button it tells her the time (wristwatch version) or by doing a clap (wall clock / alarm clock version).

Since I personally know other people who have this condition who speak other languages, it would be great to be able to automatically download the audios of the hours of other languages, instead of having to "do it manually"; I know that there are already devices that fulfill this task, but I would like to achieve this goal to give my sister a useful gift, and by the way, help other people.

My question is, how can I "download" the embedded audio in this link and save it to an SD?

https://translate.google.com/translate_tts?ie=UTF-8&q=It%27s+half+past+five+in+the+afternoon&tl=en&client=tw-ob&ttsspeed=1

English is not my mother tongue, sorry if I make mistakes.
Thanks.
User avatar
By QuickFix
#92837 I had to remove the UTF8 part from the given URL or I would get a 404, but I had the option in Chrome to save the file to MP3 without any problem (I had to ZIP it to be able to be able to attach it to this reply).
translate_tts..png
You do not have the required permissions to view the files attached to this post.
User avatar
By GalactusX31
#92839 Thanks for the reply, but my intention is to use esp8266, esp32 or even D1 wemos plus one SD module for direct download audios, you know,
- Generate links to Google tts using the arduino library.
- Send the request (http.GET?) And download/write the enbebed audio to the SD module for later use.
User avatar
By GalactusX31
#92913 EUREKA !!

After days of looking for information, and looking for very complicated ways, the solution was under my nose and I did not realize how easy it was.

Code: Select all#include <SD.h>
#include <SPI.h>
#include <WiFi.h>
#include <HTTPClient.h>

HTTPClient http;

const char* ssid = "MIWIFI_2G_dGTF";
const char* password =  "MtFDtEDp";

// String variable just to do the test
String URL = "https://translate.google.com/translate_tts?ie=UTF-8&q=It%27s+half+past+five+in+the+afternoon&tl=en&client=tw-ob&ttsspeed=1";

String file_name = "/123.mp3"; //Random file name just to do the test

void setup() {

  Serial.begin(115200);

  WiFi.begin(ssid, password); // Pass the WIFI parameters and start connection

  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi..");
  }
  Serial.println("Connected to the WiFi network");

// Start the SD card and check if it is present
  Serial.println("Initializing SD card...");
  if (!SD.begin(5)) { // see if the card is present and can be initialised.
    Serial.println("Card failed or not present, no SD Card data logging possible...");
  }
  else{
    Serial.println("Card initialised... file access enabled...");
  }
}

void loop() {
    if(WiFi.status() == WL_CONNECTED) {

        Serial.println("[HTTP] Begin...");

        http.begin(URL); //We make the call to the address

        int httpCode = http.GET(); // We capture the code returned by the URL address
       
        if(httpCode == 200) { //Code 200 means that everything has gone well
         
          if (SD.exists(file_name)) { // If the test file exists, delete it
            SD.remove(file_name);
            Serial.println("File exist, removed ..");
          }
         
          File f = SD.open(file_name, FILE_WRITE); // We create the file in writing mode
         
          if (!f) {
            Serial.println("Could not create file");
            while (1);
          } else {
            Serial.println("File was created");
          }
          //We take the data from the embedded audio file from the URL
          //and temporarily save it in a string variable
          String payload = http.getString();

          f.print(payload); // We write the data in the test file and close it
          f.close();
         
        } else {
            // If the call to the URL address failed, we print the error code
            Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
            Serial.println("");
        }
        http.end(); // We close/end the http connection
    }
    delay(10000);
}



This is just a crude example of how I have achieved it, now it's time to put everything together in my big project and make it work correctly.

I hope that the time I invested can help others in their personal projects.

Modules I have used to test the code above:
- SD Card Reader
- ESP32-WROOM 32