Commits

Jody McAdams committed ff55f24

Made an Emic 2 text to speech module library and used it in a demo

Comments (0)

Files changed (6)

ComponentExamples/Emic2TextToSpeechModule/Emic2TextToSpeechModule.ino

 /*
   
-  Emic 2 Text-to-Speech Module: Basic Demonstration       
+  Emic 2 Text-to-Speech Module: Full Demo      
                                                          
-  Author: Joe Grand [www.grandideastudio.com]             
-  Contact: support@parallax.com                            
-  
-  Program Description:
-  
-  This program provides a simple demonstration of the Emic 2 Text-to-Speech
-  Module. Please refer to the product manual for full details of system 
-  functionality and capabilities.
-
-  Revisions:
-  
-  1.0 (February 13, 2012): Initial release
+  Author: Jody McAdams         
+  Contact: jodymcadams@gmail.com                           
   
 */
 
 // include the SoftwareSerial library so we can use it to talk to the Emic 2 module
 #include <SoftwareSerial.h>
+#include <Emic2TextToSpeechModule.h>
 
-#define rxPin 50    // Serial input (connects to Emic 2 SOUT)
-#define txPin 51   // Serial output (connects to Emic 2 SIN)
-#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);
-
+Emic2TextToSpeechModule* pTTS = NULL;
 
 void setup()  // Set up code called once on start-up
 {
-  // define pin modes
-  pinMode(ledPin, OUTPUT);
-  pinMode(rxPin, INPUT);
-  pinMode(txPin, OUTPUT);
+  pTTS = new Emic2TextToSpeechModule(50,51,13);
+  //pTTS->PrintAvailableCommands();
   
-  // set the data rate for the SoftwareSerial port
-  emicSerial.begin(9600);
-
-  digitalWrite(ledPin, LOW);  // turn LED off
+  //pTTS->SetSpeakingRate(600);
+  pTTS->SetParser(0);
   
-  /*
-    When the Emic 2 powers on, it takes about 3 seconds for it to successfully
-    intialize. 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
+  pTTS->SetVolume(0);
+  pTTS->SetVoice(3);
+  
+  pTTS->Say("Do you know how much I love my beiba?");
+  pTTS->SetVoice(0);
+  //pTTS->SetSpeakingRate(600);
+  pTTS->Say("/\\I really want my beiba to/\\know I __love her more than/\\>>pizza or __even videohgaymes!");
 }
 
 void loop()  // Main code, to run repeatedly
 {
-  // Speak some text
-  emicSerial.print('S');
-  emicSerial.print("Hello. My name is the Emic 2 Text-to-Speech module. I would like to sing you a song.");  // 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(500);    // 1/2 second delay
-    
-  // Sing a song
-  emicSerial.print("D0\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);
-
-  while(1)      // Demonstration complete!
-  {
-    delay(500);
-    digitalWrite(ledPin, HIGH);
-    delay(500);              
-    digitalWrite(ledPin, LOW);
-  }
+  
 }
 
 

Libraries/Animation/keywords.txt

 ###################################
-# Syntax Coloring Map For NewPing
+# Syntax Coloring Map For Animation
 ###################################
 
 ###################################

Libraries/Emic2TextToSpeechModule/Emic2TextToSpeechModule..cpp

+//Author: Jody McAdams
+//Website: http://www.jodymcadams.com
+
+#include "Emic2TextToSpeechModule.h"
+#include <Arduino.h>
+
+Emic2TextToSpeechModule::Emic2TextToSpeechModule(int rxPin, int txPin, int ledPin)
+{
+	this->ledPin = ledPin;
+	pEmicSerial = new SoftwareSerial(rxPin, txPin);
+	
+	// define pin modes
+	pinMode(ledPin, OUTPUT);
+	pinMode(rxPin, INPUT);
+	pinMode(txPin, OUTPUT);
+	
+	// set the data rate for the SoftwareSerial port
+	pEmicSerial->begin(9600);
+	
+	digitalWrite(ledPin, LOW);  // turn LED off
+	
+	
+	// When the Emic 2 powers on, it takes about 3 seconds for it to successfully
+	// intialize. 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 ":"
+	
+	pEmicSerial->print('\n');             // Send a CR in case the system is already up
+	while (pEmicSerial->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
+	pEmicSerial->flush();                 // Flush the receive buffer
+}
+
+void Emic2TextToSpeechModule::SendCommand(unsigned char command, int value)
+{
+	pEmicSerial->print(command);
+	pEmicSerial->print(value);
+	pEmicSerial->print('\n');
+	
+	while (pEmicSerial->read() != ':');   // Wait here until the Emic 2 responds with a ":" indicating it's ready to accept the next command
+}
+
+void Emic2TextToSpeechModule::SendCommand(unsigned char command)
+{
+	pEmicSerial->print(command);
+	pEmicSerial->print('\n');
+	
+	while (pEmicSerial->read() != ':');   // Wait here until the Emic 2 responds with a ":" indicating it's ready to accept the next command
+}
+
+void Emic2TextToSpeechModule::SetVolume(int volumeDB)
+{
+	SendCommand('V',volumeDB);
+}
+
+
+void Emic2TextToSpeechModule::SetVoice(int voiceNumber)
+{
+	SendCommand('N',voiceNumber);
+}
+
+void Emic2TextToSpeechModule::SetSpeakingRate(int rate)
+{
+	SendCommand('W',rate);
+}
+
+void Emic2TextToSpeechModule::SetParser(int parser)
+{
+	SendCommand('P',parser);
+}
+
+void Emic2TextToSpeechModule::PrintAvailableCommands()
+{
+	SendCommand('H');
+}
+
+void Emic2TextToSpeechModule::Say(const char* stringToSay)
+{
+	pEmicSerial->print('S');
+	pEmicSerial->print(stringToSay);
+	pEmicSerial->print('\n');
+	
+	digitalWrite(ledPin, HIGH);         // Turn on LED while Emic is outputting audio
+	while (pEmicSerial->read() != ':');   // Wait here until the Emic 2 responds with a ":" indicating it's ready to accept the next command
+	digitalWrite(ledPin, LOW);
+}

Libraries/Emic2TextToSpeechModule/Emic2TextToSpeechModule.h

+//Author: Jody McAdams
+//Website: http://www.jodymcadams.com
+
+#ifndef Emic2TextToSpeechModule_h
+#define Emic2TextToSpeechModule_h
+
+#include <SoftwareSerial.h>
+
+class Emic2TextToSpeechModule
+{
+public:
+	Emic2TextToSpeechModule(int rxPin, int txPin, int ledPin);
+	void Say(const char* stringToSay);
+	void SetVoice(int voiceNumber); //0 to 8
+	void SetVolume(int volumeDB); //-48 to 18
+	void SetSpeakingRate(int rate); //75-600 (Doesn't seem to work)
+	void SetParser(int parser); //0 (DECTalk), 1 (Epson)
+	void PrintAvailableCommands(); //(Doesn't seem to work)
+	
+private:
+    void SendCommand(unsigned char command, int value);
+    void SendCommand(unsigned char command);
+    
+    // set up a new serial port
+	
+    SoftwareSerial* pEmicSerial;
+    int ledPin;
+};
+
+#endif

Libraries/Emic2TextToSpeechModule/keywords.txt

+###################################
+# Syntax Coloring Map For Emic2TextToSpeechModule
+###################################
+
+###################################
+# Datatypes (KEYWORD1)
+###################################
+
+
+###################################
+# Methods and Functions (KEYWORD2)
+###################################
+
+
+###################################
+# Constants (LITERAL1)
+###################################

Libraries/Math/keywords.txt

 ###################################
-# Syntax Coloring Map For NewPing
+# Syntax Coloring Map For MathUtil
 ###################################
 
 ###################################
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.