Emic2 code for the propeller
Jim the Hermit
Posts: 79
Can someone post code for the emic2? just a spin file saying a few things.
I got the demo program to work, but I don't know how to change the volume or the voice, pitch, etc.
The demo uses the Parallax Serial Terminal, which I want to get rid of (I successfully hook up my LCD to do the same thing.)
I can't delete pst from OBJ because something called pst#NL gets sent to the emic for some reason.
The emic2 manual has no examples in a computer language as far as I can tell.
I got the demo program to work, but I don't know how to change the volume or the voice, pitch, etc.
The demo uses the Parallax Serial Terminal, which I want to get rid of (I successfully hook up my LCD to do the same thing.)
I can't delete pst from OBJ because something called pst#NL gets sent to the emic for some reason.
The emic2 manual has no examples in a computer language as far as I can tell.
Example:
:V-10
:
Comments
Remember the ":" is what the EMIC 2 returns. It isn't part of the command.
In your example, if you were using PST as a serial device you'd use:
Pst.str(string("v-10", 13))Would set the volume to -10.
And to say "Hello World" use:
Pst.str(string("SHello World", 13))The "S" is for "say" or "speak" (I don't remember which).
I'm pretty sure the Emic 2 doesn't care about case.
Have you seen this thread?
Here is an example playing Happy Birthday...
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 ' ------- Pin assigments ------ green = 0 blue = 1 red = 2 OBJ pst : "Parallax Serial Terminal" ' Debug Terminal serial : "FullDuplexSerial" ' Full Duplex Serial PUB main dira[0..2]~~ ' set to outputs (i.e. 1) outa[0..2]~~ ' set high serial.Start(7, 6, 00, 9_600) ' Start serial port, normal mode, 9600bps serial.TX(pst#NL) ' Send a CR in case the system is already up repeat until serial.RxCheck == ":" ' When the Emic 2 has initialized and is ready, it will send a single ':' character, so wait here until we receive it waitcnt(clkfreq / 100 + cnt) ' Delay 10mS serial.RxFlush ' Flush the receive buffer serial.Str(String("R", pst#NL)) 'reset to defaults repeat until serial.RxCheck == ":" serial.Str(String("P0", pst#NL)) 'set Parser to DecTalk repeat until serial.RxCheck == ":" ' serial.Str(String("N2", pst#NL)) 'voice ' repeat until serial.RxCheck == ":" serial.Str(String("V-4", pst#NL)) 'volume -48 to 18 repeat until serial.RxCheck == ":" serial.Str(String("W240", pst#NL)) 'words per minute repeat until serial.RxCheck == ":" serial.TX("S") serial.Str(@HappyBday) ' Send the desired string to convert to speech (stored in the DAT section below) serial.TX(pst#NL) repeat until serial.RxCheck == ":" PUB Delay(mS) ' Delay in milliseconds waitcnt(clkfreq / 1000 * mS + cnt) DAT HappyBday byte "[:phone arpa speak on][:rate 200][:n0]" byte "[hxae<300,10>piy<300,10>brrrx<600,12>th<100>dey<600,10>tuw<600,15>yu<1200,14>_<300>" byte "hxae<300,10>piy<300,10>brrrx<600,12>th<100>dey<600,10>tuw<600,17>yu<1200,15>_<300>" byte "hxae<300,10>piy<300,10>brrrx<600,22>th<100>dey<600,19>dih<600,15>r" byte " eh<600,14>m<100,12>ih<350,12>k_<120>_<300>" byte "hxae<300,20>piy<300,20>brrrx<600,19>th<100>dey<600,15> tuw<600,17> yu<1200,15>]" byte "[:n0]", 0You need some sort of serial driver in order to communicate with the Emic 2. So yes it does take up some RAM but there's not much you can do about it. If you used BST, you can have it remove unused methods which would cut down on the amount of ram used.
Since the Emic 2 communicates at 9600 bps, you could probably get away with using Simple Serial which doesn't launch in a separate cog. I personally think you'll have more problems than it would be worth using Simple Serial though.
If you're going to want to use a debug window, you could use a multi-port serial driver which wouldn't take up much more RAM than the single port driver.
Thanks for your time.
Dave
{{ ┌─────────────────────────────────────────────────────────┐ │ Emic 2 Text-to-Speech Module: Basic Demonstration │ │ │ │ Author: Joe Grand [www.grandideastudio.com] │ │ Contact: support@parallax.com │ │ │ │ See end of file for terms of use. │ └─────────────────────────────────────────────────────────┘ Program Description: This program demonstrates the Emic 2 Text-to-Speech Module. Debug messages are displayed in the Parallax Serial Terminal. Please refer to the Emic 2 product manual for full details of functionality and capabilities. Emic 2 Connections (4 pin male header) ──────────────────────────────────────────────── SIN ────── P6 SOUT ────── P7 VCC ────── +5V (VDD) GND ──────┐  GND (VSS) Revisions: 1.0 (February 14, 2012): Initial release }} CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 EMIC_TX = 6 ' Serial output (connects to Emic 2 SIN) EMIC_RX = 7 ' Serial input (connects to Emic 2 SOUT) VAR OBJ pst : "Parallax Serial Terminal" ' Debug Terminal serial : "FullDuplexSerial" ' Full Duplex Serial PUB main pst.Start(115_200) ' Set Parallax Serial Terminal to 115.2kbps pst.Clear ' Clear PST screen pst.Str(@InitHeader) ' Print header; uses string in DAT section. ' Set-up serial port for communication with the Emic 2 serial.Start(EMIC_RX, EMIC_TX, %0000, 9_600) ' Start serial port, normal mode, 9600bps {{ 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 ":" }} pst.Str(String("Waiting for Emic 2...")) serial.TX(pst#NL) ' Send a CR in case the system is already up repeat until serial.RxCheck == ":" ' When the Emic 2 has initialized and is ready, it will send a single ':' character, so wait here until we receive it pst.Str(String("Ready!", pst#NL)) waitcnt(clkfreq / 100 + cnt) ' Delay 10mS serial.RxFlush ' Flush the receive buffer pst.Str(String("Speaking some text...")) serial.TX("S") serial.Str(@TextString) ' Send the desired string to convert to speech (stored in the DAT section below) serial.TX(pst#NL) repeat until serial.RxCheck == ":" ' Wait here until the Emic 2 responds with a ":" indicating it's ready to accept the next command pst.Str(String("Done!", pst#NL)) waitcnt(clkfreq >> 1 + cnt) ' Delay 1/2 second pst.Str(String("Singing a song...")) serial.Str(String("D1", pst#NL)) ' Play the built-in demonstration song. See the product manual for exact settings used to create this song. repeat until serial.RxCheck == ":" ' Wait here until the Emic 2 responds with a ":" indicating it's ready to accept the next command pst.Str(String("Done!", pst#NL)) DAT InitHeader byte "Emic 2 Text-to-Speech Module Demonstration", pst#NL, pst#NL, 0 TextString byte "Hello. My name is the Emic 2 Text-to-Speech module. I would like to sing you a song.", 0 {{ ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ TERMS OF USE: MIT License │ ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation │ │files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, │ │modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│ │is furnished to do so, subject to the following conditions: │ │ │ │The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.│ │ │ │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE │ │WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR │ │COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │ │ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ }}That would be a very low volume setting. Have you tried "V10"?
I don't recall what the max setting is, but I'm pretty sure it's a positive number.
Did you also send a carriage return?
Edit: The volume range is -48 to 18.
I know I've used the volume setting on my Emic2 without a problem.
One of the things that I tried was to add:
Pst.str(string("v18", 13))such as:
pst.Str(String("Waiting for Emic 2...")) serial.TX(pst#NL) ' Send a CR in case the system is already up repeat until serial.RxCheck == ":" ' When the Emic 2 has initialized and is ready, it will send a single ':' character, so wait here until we receive it pst.Str(String("Ready!", pst#NL)) serial.RxFlush ' Flush the receive buffer Pst.str(string("v18", 13)) serial.TX("S") serial.Str(@Introduction) ' Send the desired string to convert to speech (stored in the DAT section below) serial.TX(pst#NL) repeat until serial.RxCheck == ":" ' Wait here until the Emic 2 responds with a ":" indicating it's ready to accept the next commandbut no luckAny suggestions?
BTW here is another thread where someone was having the same problem. You posted your code at #5. I tried adding what you did, but still no joy. http://forums.parallax.com/showthread.php/141461-Emic-2-and-Parallax-Terminal
I'm using a pair of earbuds. I don't have a problem hearing anything and I can use the "##" to make it say a word softer. I just can't get it to be louder of softer using
Pst.str(string("v18", 13))
I know that I must be making some small mistake.
I think you're right.
I tried it again just now with the uppercase "V" and there is no difference.
Pst.str(string("V18", 13))
{{ ┌─────────────────────────────────────────────────────────┐ │ Emic 2 Text-to-Speech Module: Basic Demonstration │ │ │ │ Author: Joe Grand [www.grandideastudio.com] │ │ Contact: support@parallax.com │ │ │ │ See end of file for terms of use. │ └─────────────────────────────────────────────────────────┘ Program Description: This program demonstrates the Emic 2 Text-to-Speech Module. Debug messages are displayed in the Parallax Serial Terminal. Please refer to the Emic 2 product manual for full details of functionality and capabilities. Emic 2 Connections (4 pin male header) ──────────────────────────────────────────────── SIN ────── P6 SOUT ────── P7 VCC ────── +5V (VDD) GND ──────┐  GND (VSS) Revisions: 1.0 (February 14, 2012): Initial release }} CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 EMIC_TX = 6 ' Serial output (connects to Emic 2 SIN) EMIC_RX = 7 ' Serial input (connects to Emic 2 SOUT) VAR OBJ pst : "Parallax Serial Terminal" ' Debug Terminal serial : "FullDuplexSerial" ' Full Duplex Serial PUB main pst.Start(115_200) ' Set Parallax Serial Terminal to 115.2kbps pst.Clear ' Clear PST screen pst.Str(@InitHeader) ' Print header; uses string in DAT section. ' Set-up serial port for communication with the Emic 2 serial.Start(EMIC_RX, EMIC_TX, %0000, 9_600) ' Start serial port, normal mode, 9600bps {{ 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 ":" }} pst.Str(String("Waiting for Emic 2...")) serial.TX(pst#NL) ' Send a CR in case the system is already up repeat until serial.RxCheck == ":" ' When the Emic 2 has initialized and is ready, it will send a single ':' character, so wait here until we receive it pst.Str(String("Ready!", pst#NL)) waitcnt(clkfreq / 100 + cnt) ' Delay 10mS serial.RxFlush ' Flush the receive buffer pst.Str(String("Speaking some text...")) Pst.str(string("V18", 13)) serial.TX("S") serial.Str(@TextString) ' Send the desired string to convert to speech (stored in the DAT section below) serial.TX(pst#NL) repeat until serial.RxCheck == ":" ' Wait here until the Emic 2 responds with a ":" indicating it's ready to accept the next command pst.Str(String("Done!", pst#NL)) waitcnt(clkfreq >> 1 + cnt) ' Delay 1/2 second {{ pst.Str(String("Singing a song...")) serial.Str(String("D1", pst#NL)) ' Play the built-in demonstration song. See the product manual for exact settings used to create this song. repeat until serial.RxCheck == ":" ' Wait here until the Emic 2 responds with a ":" indicating it's ready to accept the next command pst.Str(String("Done!", pst#NL)) }} DAT InitHeader byte "Emic 2 Text-to-Speech Module Demonstration", pst#NL, pst#NL, 0 TextString byte "Hello. My name is the Emic 2 Text-to-Speech module. I would like to sing you a song.", 0Emic2_Demo2 - Archive [Date 2013.07.10 Time 14.21].zip
I'll test the code soon.
Here's another demo to make it easier to tell if the volume is changing.
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 EMIC_TX = 6 ' Serial output (connects to Emic 2 SIN) EMIC_RX = 7 ' Serial input (connects to Emic 2 SOUT) MAX_VOL = 18 MIN_VOL = -48 VOL_STEP = 6 VAR OBJ pst : "Parallax Serial Terminal" ' Debug Terminal serial : "FullDuplexSerial" ' Full Duplex Serial PUB main pst.Start(115_200) ' Set Parallax Serial Terminal to 115.2kbps pst.Clear ' Clear PST screen pst.Str(@InitHeader) ' Print header; uses string in DAT section. ' Set-up serial port for communication with the Emic 2 serial.Start(EMIC_RX, EMIC_TX, %0000, 9_600) ' Start serial port, normal mode, 9600bps {{ 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 ":" }} pst.Str(String("Waiting for Emic 2...")) serial.TX(pst#NL) ' Send a CR in case the system is already up repeat until serial.RxCheck == ":" ' When the Emic 2 has initialized and is ready, it will send a single ':' character, so wait here until we receive it pst.Str(String("Ready!", pst#NL)) waitcnt(clkfreq / 100 + cnt) ' Delay 10mS serial.RxFlush ' Flush the receive buffer pst.Str(String("Set and Speak Volume", pst#NL)) repeat repeat result from MIN_VOL to MAX_VOL - 1 step VOL_STEP SetAndSayVolume(result) repeat result from MAX_VOL to MIN_VOL + 1 step VOL_STEP SetAndSayVolume(result) PUB SetAndSayVolume(volume) serial.TX("V") serial.dec(volume) serial.TX(pst#NL) serial.rxtime(500) serial.TX("S") serial.Str(@textTheVol) serial.dec(volume) pst.Str(@textTheVol) pst.dec(volume) serial.TX(pst#NL) pst.Char(pst#NL) serial.rxtime(500) waitcnt(clkfreq * 6 + cnt) DAT InitHeader byte "Emic 2 Text-to-Speech Module Demonstration", pst#NL, pst#NL, 0 textTheVol byte "The volume of the E mic 2 is now set to ", 0The volume gets very loud at 18 and I can barely hear it when it's -30.
Hey Duane, thanks!
I got it working on my set-up. It seems like the key was to break the volume command into three part (two might work, but that's for tomorrow). Changed this:
Pst.str(string("V18", 13))to this:serial.TX("V") serial.dec(18) serial.TX(pst#NL)Thanks again for all of your help and for taking the time in getting out your speaker, setting it up, and making the variable volume demo.
Dave
So the problem was your using the wrong serial line. I didn't notice it until now.
You're right! I changed it to the serial object serial.str(string("V18", 13)) and it works just fine. Details? hu? they make a difference.
Dave
Sometimes those details become invisible from looking at the code so long. Sometimes a second set of eyes helps.
You're very welcome.