Spark Core Text-to-Speech using Emic2 Module

Spark Core TTS Sample using Emic2 Text-to-Speech Module

Here is a project using Emic2 Text-to-Speech Module and :spark:. Emic2 is simple to use TTS module. It has all the features of a common TTS engine. We change the volume, pitch, language, etc… Also we can have 8 different voice. We can program the Emic2 using Serial. We just want to send some text to the board using Serial and the board will say it. I have used Dan Malec’s Emic2TtsModule library from SocialChatter application and ported to :spark: (this was a very simple port).

This sample has two different applications, the :spark: app and the Web App to access the Emic2 TTS Module. The :spark: application exposes different method to speak, change properties, etc… The Web App calls these methods to access the Emic2. The Web App is just for a demonstration purpose.

Here is a demo video http://youtu.be/zoSZNZNvt78 (sorry about the quality, I am very bad in handling camera).

Screenshots
enter image description here

enter image description here

Things to do:

  1. Optimize the :spark: App to reduce memory consumption.

  2. Find out a method to pass more than 63 characters (Spark.function can
    take only 63 characters as argument) (A simple method is to define a
    start and end of stream and parse it in :spark: app).

5 Likes

Hmm…

  1. TCPServer on the Core, your web app would act as a TCPClient and POST or PUT data to the Core. You would probably have to forward a port on your router though, and know your home/work IP address ahead of time. Or use a dynamic dns service to always have a way to get to your home/work connection. If you were using it on a local network you could skip the port forwarding stuff.

  2. TCPClient on the Core, Node.js server in the middle, your web app would act as a TCPClient and talk WebSockets to the Core. Example 1.

  3. TCPClient on the Core, PHP server in the middle, your web app would act as a TCPClient of the PHP Server which would do two things: use Spark.function() send a URL to the Core which would be link back to the PHP server for a simple GET request that gave the Core as much data as you could buffer. The data would come from session memory, database, or a temporary text file on the server.

2 Likes

Thank you @BDub, I think I should work on one of these this weekend.

Looking good on hackster.io!!! Neat project, @krvarma!

1 Like

Thank you @Teke for the feedback!

Can anyone spare the time to give me step-by step directions to put the Emic2TTS.h library on my computer. I have downloaded it but where do I put it so that Particle Build will find it? I am wanting to use the EMIC2 on a Photon. I have had success with it on Arduino but now want to move my application onto Photon. Thanks for your help.

@davidsproule, if you are using online Particle IDE, then you create a project. Create new file by clicking on the + button at the top right. name if Emic2TTS. Copy the contents of the Emic2TTS.h and .cpp fie. That’s it, now you can compile it

If you are using Particle Dev, then download and copy the files in a folder and open the folder.

Hope this will help you to get started.

But since the library is already uploaded into the library repository of build you can just import it the standard way.
Have a look at the docs “using libraries”.
https://docs.particle.io/guide/getting-started/build/electron/#using-libraries

Unless you intend to alter the library.

This can only be done with copies of the library files as @krvaram has already explained.

1 Like

Thank you guys. I just got the demo going following your direction.
Much appreciated. I’ll give you a further post when I get my project going.

1 Like

Again I have run into a brick wall. I have flashed TTS.ino with EMIC2.CPP and EMIC2TTS.h to my Photon, and TTS.html is on my browser. I have pasted my device and ID numbers and typed in some text to send, but no results. When I go to Spark dashboard it lists my Photon as online and notes two functions: speak & setProp. Entering some text in speak sends it through the Photon & EMIC2 with good sound. This would seem to suggest that the Photon is working OK but there is a problem at the html end. I had hoped your html would work for me and I would then adapt it to my needs. Any suggestions? All I think I need to start is three pieces of code: a line to input some text, a line to send the text to the cloud, and possibly an error/OK indication.
I will appreciate any help you can offer this old guy.
Dave

@davidsproule, I hope you have downloaded all the web app files, .JS, .CSS, and .HTML files.Could you please let us know whether your are getting any error or not?

Also can you please take JavaScript console and see any errors are coming there, following hotkeys can be used to get the console in most of the browsers.

Use the keyboard shortcut Command + Option + J (Mac) or Control + Shift + J (Windows/Linux).

This way we can figure our what went wrong in your case. Let us know the progress.

1 Like

I had not downloaded ALL the web app files. I only had tts.html open on by browser. How do I use jquery.blockUI.js and css. As mentioned before with your help, I have flashed tts.ino (with added EMIC2TTS.cpp and Emic2TTS.h). I can try to do the tests you suggested, but I suspect not having .js and .cpp in the mix may be the problem.
Please continue your great help.
Dave

@davidsproule, please download all the files in the Web App folder and copy to a folder. Now you can open the .HTML file. The .JS and the CSS folder is used by the HTML file. You don’t need any .CPP file to use the Web App, only .JS File, CSS Folder and .HTML file is needed.

Thank you for all your help. I created a new directory and put all the relevant files in it. Still no joy. Then I went to the top of your Project Share page and used the Download ZIP button. I put the download in that created folder, unzipped and tried again. It was music to my ears. Interestingly, I now have two slightly different web pages - one with underlines between the sections. Both now work. Thanks again. Have a wonderful Easter.

1 Like

krvarma, thank you for sharing your super project and most helpful advice when I got into trouble. I have adapted your code to send text to a Teddy Ruxpin teddy bear. The major change was to insert parsing (as below) so that Ted’s mouth would open and close at each space in the line of text. It works except too much time elapses between words. Have you any suggestions for a speedup? The following fits in your TTS.INO code.

//Speak the text
{
    urlDecode(text);
    textToSpeak = "";
    textToSpeak += text;
 
    do
    {
    spacePosition = textToSpeak.indexOf(' ');
    if (spacePosition != -1)
        {
        emic.say(textToSpeak.substring(0, spacePosition));
        mouth();  // routine to open&close mouth
        textToSpeak=textToSpeak.substring(spacePosition+1,textToSpeak.length());
        }
    else 
        {   // here after last space is found
        if(textToSpeak.length() > 0)
            {
            emic.say(textToSpeak);
            mouth();
            blink();
            }
        }
    }
    while(spacePosition >=0);
        
    return 1;
}
1 Like

@davidsproule, I think there will be a delay in TTS also. This is because the input to the EMIC is word by word. This could be a problem.

I was surprised by the delay because before I transferred the project to Photon I had it working well on Arduino. The only delays seemed to be the intentional ones in my code to allow the mouth motor time to operate before being shut off and then reversed. The timing was quite good.
I’ll keep looking.