Benutzer-Werkzeuge

Webseiten-Werkzeuge


Seitenleiste

bauteile:emic_2

Emic 2: Text-to-Speech Module

Ein simpler Schaltplan für das Modul ist in der Dokumentation zu finden. Sobald alles verkabelt ist könnt ihr dieses Beispielsprogramm testen:

// include the SoftwareSerial library so we can use it to talk to the Emic 2 module
#include <SoftwareSerial.h>
 
#define rxPin   10  // Serial input (connects to Emic 2's SOUT pin)
#define txPin   11  // Serial output (connects to Emic 2's SIN pin)
#define ledPin  13  // Most Arduino boards have an on-board LED on this pin
 
// set up a new serial port
SoftwareSerial emicSerial =  SoftwareSerial(rxPin, txPin);
 
void setup()  // Set up code called once on start-up
{
  // define pin modes
  pinMode(ledPin, OUTPUT);
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
 
  // set the data rate for the SoftwareSerial port
  emicSerial.begin(9600);
 
  digitalWrite(ledPin, LOW);  // turn LED off
 
  /*
    When the Emic 2 powers on, it takes about 3 seconds for it to successfully
    initialize. It then sends a ":" character to indicate it's ready to accept
    commands. If the Emic 2 is already initialized, a CR will also cause it
    to send a ":"
  */
  emicSerial.print('\n');             // Send a CR in case the system is already up
  while (emicSerial.read() != ':');   // When the Emic 2 has initialized and is ready, it will send a single ':' character, so wait here until we receive it
  delay(10);                          // Short delay
  emicSerial.flush();                 // Flush the receive buffer
}
 
void loop()  // Main code, to run repeatedly
{
  emicSerial.print('V');
  emicSerial.print("0");  // Set volume to 0dB (range -48dB (soft) to 18dB (loud))
  emicSerial.print('\n');
  digitalWrite(ledPin, HIGH);         // Turn on LED while Emic is outputting audio
  while (emicSerial.read() != ':');   // Wait here until the Emic 2 responds with a ":" indicating it's ready to accept the next command
  digitalWrite(ledPin, LOW);
  // Every robot should inherit the three laws of robotics!
  // 1. Law of robotics
  emicSerial.print('S');
  emicSerial.print("A robot may not injure a human being or, through inaction, allow a human being to come to harm.");  // Send the desired string to convert to speech
  emicSerial.print('\n');
  digitalWrite(ledPin, HIGH);         // Turn on LED while Emic is outputting audio
  while (emicSerial.read() != ':');   // Wait here until the Emic 2 responds with a ":" indicating it's ready to accept the next command
  digitalWrite(ledPin, LOW);
  // 2. Law of robotics
  emicSerial.print('S');
  emicSerial.print("A robot must obey the orders given it by human beings, except where such orders would conflict with the First Law.");  // Send the desired string to convert to speech
  emicSerial.print('\n');
  digitalWrite(ledPin, HIGH);         // Turn on LED while Emic is outputting audio
  while (emicSerial.read() != ':');   // Wait here until the Emic 2 responds with a ":" indicating it's ready to accept the next command
  digitalWrite(ledPin, LOW);
  // 3. Law of robotics
  emicSerial.print('S');
  emicSerial.print("A robot must protect its own existence as long as such protection does not conflict with the First or Second Laws.");  // Send the desired string to convert to speech
  emicSerial.print('\n');
  digitalWrite(ledPin, HIGH);         // Turn on LED while Emic is outputting audio
  while (emicSerial.read() != ':');   // Wait here until the Emic 2 responds with a ":" indicating it's ready to accept the next command
  digitalWrite(ledPin, LOW);
 
  delay(5000);
}

Hier ist eine Liste von Befehlen, mit welchen man die Einstellungen ändern kann, z.B. die Sprache (Englisch / Spanisch), Stimme, Lautstärke usw.: http://bradsduino.blogspot.de/2013/04/emic-2-text-to-speech-module-arduino-due.html. Ein Beispiel, wie man die Lautstärke mit solchen Befehlen ändert, ist bereits im Code oben erhalten. Die Sprache kann man z.B. so ändern:

  emicSerial.print("L2"); // fuer lateinamerikanisches Spanisch
  emicSerial.print('\n');

Alternative: Talkie-Bibliothek

Mit der Talkie-Bibiliothek kann man Sprachausgabe machen, ohne einen speziellen Modul, nur mit einem Lautsprecher und Verstärker. Hier ist ein Link zur Bibliothek mit Installationsanweisungen. Hier und hier wird erklärt, wie man die Schaltung aufbaut.

Die „vorgefertigten“ Vokabeln sind in der englischen Sprache verfügbar. Theoretisch kann man eigene Vokabeln zusammenstellen, ist aber mit Aufwand verbunden.

bauteile/emic_2.txt · Zuletzt geändert: 2021/02/11 18:13 von d.golovko