[tutorial] EMIC2

EMIC2 Tutorial from codebender on Vimeo.

This is a tutorial on the EMIC2 library. EMIC2 is an Arduino library for interfacing the Emic 2 Text-to-Speech module. With this library, you can change the characteristics of the module’s speech through the use of a simple interface that hides away the technical stuff, and allows for a more natural way of control. You can send messages that are provided as an immediate argument to a method, or by reference through a file in an SD card.


Let’s see what we can do with the library.

Make the following connections with your Arduino, the Emic2 module, and the speaker.


The EMIC2 library has two accompanying examples. The SpeakMessage example exposes some of the functionality of the library, and the SpeakMsgFromSD demonstrates how we can use an SD card to read text files.


Let’s examine the code.

First, we include the EMIC2 library, along with SoftwareSerial and SD that are needed by our library (lines 3-5). We specify the RX and TX pins we’ll use for the serial communication with the module (lines 9-10), and then we create an EMIC2 instance (line 12). Inside the setup function, we’ll have to initialize the instance with the RX and TX pins (line 19).

And then we see the first method (line 21). We can use setVoice to select one of 9 voices there are available on the module. There are voices comprising male, female, and child. The default voice is number zero and it’s a male voice.

Moving on to the loop, we fall into the speak method (line 28). We can use speak with a char array, a string, or a numeric data type, and send that message to the module to convert it to speech. Next, we send another message, and then we see the use of the tilde operator (lines 32/34), ~. We can use tilde with an EMIC2 instance while a message is playing on the module to pause and unpause playback.

Next, we can use setRate (line 38) to set the speaking rate to a value within a range, and resetRate (line 40) to reset it to the default value of 200 words/minute. We can also use the double greater than (line 44), >>, and double less than (line 46), <<, operators to increase and decrease the speaking rate, respectively.

Next, we can use setVolume (line 50) to set the volume level to a value within a range, and resetVolume (line 52) to reset it to the default value of 0dB. We can also use the += (line 59) and -= (line 56) operators to raise and lower the volume level, respectively. And finally there are the prefix ++ (line 60) and -- (line 57) operators for a unit step change in the volume level.

Going further down, we meet the bang operator (line 69), !, that we can use to stop the playback on the module at any time.

And that’s pretty much the jist of it.


In this example we utilize an SD card, and in order to play something on the module, we need some files.

Load an SD card on your computer, format the card to a FAT file system, create a folder emic2, and put any files you want to be read inside this folder.

So, let’s look at the code now.

Everything is pretty much the same. The one thing we have to do is to specify the chip select pin for the SD card and provide that to the begin method.

Now, we call speak with the name of our file, and an additional argument, SD_C, to inform the method that the string we gave it, it’s not a message for the module to read, but rather it’s a filename. And then the method will start sending messages to the Emic2 module for every line in the file.

Simple as that. Initialize and send!

That’s all folks. We hope you enjoy this library, and if you have any comments or suggestions you can contact us at girder [at] codebender [dot] cc

Sounds are from freesound.org. Schematics were based on Fritzing.


  1. Larry Amati

    02 Mar 2014 15:03:56

    Can I interface to an apm 2.5 ardurover to speak sensor responses?

    • Nick Lamprianidis

      02 Mar 2014 19:52:31

      Hello Larry,
      All the Emic 2 module needs to work is a 9600 baud serial interface. If you can provide one, then you can use the module for whatever you need (i.e. speaking your sensor responses).
      As far as the library is concerned, if your microcontroller is supported by the SoftwareSerial library, then you can most probably use the EMIC2 library too.
      I hope that helps,

  2. Angel

    25 Mar 2014 07:39:44

    Hi! I am trying to import the EMIC2 library into Arduino but I get the following error when I do:

    Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException
    at processing.app.EditorToolbar.setState(EditorToolbar.java:282)
    at processing.app.EditorToolbar.deactivate(EditorToolbar.java:380)
    at processing.app.Editor.statusError(Editor.java:2573)
    at processing.app.Base.handleAddLibrary(Base.java:2425)
    at processing.app.Base$4.actionPerformed(Base.java:955)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1225)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1266)
    at java.awt.Component.processMouseEvent(Component.java:6263)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    at java.awt.Component.processEvent(Component.java:6028)
    at java.awt.Container.processEvent(Container.java:2041)
    at java.awt.Component.dispatchEventImpl(Component.java:4630)
    at java.awt.Container.dispatchEventImpl(Container.java:2099)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.java:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2475)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

  3. Angel

    25 Mar 2014 07:51:32

    UPDATE: Now when I try to add your library it gives me this error:

    The library “EMIC2-master” cannot be used. Library names must contain only basic letters and numbers.(ASCII only and no spaces, and it cannot start with a number)

  4. Michael

    28 Mar 2014 03:13:58

    very good job on the EMIC2 library but I have the same problem as they guy above – I get the same error “The library “EMIC2-master” cannot be used. Library names must contain only basic letters and numbers.(ASCII only and no spaces, and it cannot start with a number)”. have you used any unorthodox characters that maybe trigger this message?

    • Nick Lamprianidis

      07 Apr 2014 14:57:11

      Hello Michael,

      As I also explained to our friend above, when downloading a library from github, the folder containing the library has a “-master” suffix. You should delete the “-master” suffix from the library’s folder name (“EMIC2-master” becomes “EMIC2”), and then install that folder in your libraries’ directory.

      I hope that solves your problem,

  5. Javier

    16 Feb 2015 19:56:18

    Hello Is it possible to set this up and open something like HyperTerminal on windows and type what I want to say and send to the Emic2? If so, do you have sample code for this?

    Thank you,

    • Nick Lamprianidis

      18 Feb 2015 21:58:43

      Hello Javier,

      Of course it’s possible. You don’t need to do any programming for this. You just connect emic2 to your computer through a usb-to-serial converter, configure your terminal (9600 bps, 8 data bits, no parity bits, 1 stop bit, non-inverted, “enter” sends a “\n”), open the port, and just send commands, like so

      SHello World.

      You can find more details on the manual, here.

  6. Dan Reifsnyder

    04 Aug 2015 20:50:26

    Great tutorial! One quick question… how big a text file can read/buffered when reading from an SD card (or is it just read a line at a time, making size irrelevant)? Thanks!

    • Nick Lamprianidis

      09 Aug 2015 19:52:22

      Hey Dan,

      The text files are read and sent byte by byte, and a message is spoken for every line in the file. A message can have at most 1023 characters. Therefore, a line is limited to 1023 characters. For any other matter regarding the files in the SD and any memory requirements, you should consult the SD library.


  7. Hal Breidenbach

    06 Jul 2016 22:07:21

    I tried to read from the serial monitor into a String (object) and then into a string (char array) to pass:
    emic.speak(filename, chipSelect);
    This can’t seem to find the file.
    When I use:
    epic.speak(“file.txt”, chipSelect);
    the file is loaded and spoken as expected.
    Do I need to do some work on the String or string to remove line feeds? Do you have an example of this that does work?

    • Nick Lamprianidis

      09 Jul 2016 19:20:48

      Hi Hal,
      The problem, given your description, is that perhaps you don’t create the file you want to read. But even before that, you don’t really need to create a file. You can use directly your String, like so

      String str("stuff read from serial monitor");
  8. HGuzmán

    09 Nov 2016 01:02:15

    Hi, great tutorial. But how can I change the language? Which is the command?
    Thank you

  9. tasrin

    14 Mar 2017 17:29:31

    how to use emic2 for detecting obstacles with arduino and ultrasonic

  10. Artomi

    24 Aug 2017 19:22:07

    I have a problems using emic with bluetooth.
    Why data sent from bluetooth can not be read twice by emic?
    Can you tell me how it can be read many times by emic?

Comments are closed.

Stay tuned:

* we promise that we won´t spam you, never.