Go Down

### Topic: Is it possible to make Arduino talk without shield (Read 39365 times)previous topic - next topic

#### D3C3PT1C0N

#15
##### Jun 27, 2010, 03:55 pmLast Edit: Jun 27, 2010, 05:21 pm by Fredx Reason: 1
I did some changes

Quote

void loop()
{

// Takes 8 samples and sums up
for(int i = 0; i < 8; i++)
{
}

// Makes some calculations
tempc = (5.0 * tempc * 100.0) / (8.0 * 1024.0);
int tempb = tempc + 0.5;

state = !state;
Test_Speech();
}

void Test_Speech()
{
text2speech.setPitch(6); //lower values = higher voice pitch
itoa (tempb, tempx, 10); // integer to string
strcpy(text, tempx);
text2speech.say(text);
Serial.println(text);
delay(500);
}

Serial.println(text); - gives always ZERO. Wonder why?

Also i was thinking, because the speech isnt very understandable, to let it say numbers in my language.

For example,

Quote
INTEGER 1 = "ÜKS"
INTEGER 2 = "KAKS"
INTEGER 3 = "KOLM"
INTEGER 4 = "NELI"
INTEGER 5 = "VIIS"
etc.

tempb = (5.0 * tempc * 100.0) / (8.0 * 1024.0);
digit1 = tempb / 10; // get the ten's digit
digit2 = tempb % 10; // get the one's digit

IF digit1 = 1
THEN digit1 = ÜKS

IF digit1 = 2
THEN digit1 = KAKS

IF digit1 = 3
THEN digit1 = KOLM

and then the script says "KAKS KOLM" instead of "TWO THREE" (by default the speech script pronounces numbers in english one-two-three-etc)

How to do this? Any suggestions for displacing numbers ?

#### PaulS

#16
##### Jul 03, 2010, 03:07 pm
Code: [Select]
`int tempb = tempc + 0.5;`
This statement, in loop, creates a local variable, named tempb, and assigns it a value.

Code: [Select]
`itoa (tempb, tempx, 10); // integer to string`
This statement, in Test_Speech, references a global variable named tempb. This is NOT the same variable that was valued in loop.

#### PaulS

#17
##### Aug 10, 2010, 03:24 pm
Quote
No idea what to do..

The IDE told you which line caused the error.

Code: [Select]
`itoa (tempb, tempx, 10); // integer to string`
The 1st argument is the integer to be converted to a string. The 2nd argument is the string (array of characters) where the output is to be stored. The 3rd argument is the base (typically 10) to be used in the conversion.

I don't see a declaration for tempx, and I doubt that the compiler does, either. Therefore, it assumes that you will declare it as an integer, and is telling you that that is the wrong type.

Stupid ass assumption, in my opinion, but I didn't write the compiler.

#### D3C3PT1C0N

#18
##### Aug 11, 2010, 03:15 pmLast Edit: Aug 11, 2010, 04:30 pm by Fredx Reason: 1
I had mistakes in previous code. Here is the current script i'm working on:

Code: [Select]
`/*The Text To Speech library uses Timer1 to generate the PWMoutput on digital pin 10. The output signal needs to be fedto an RC filter then through an amplifier to the speaker.*/#include <TTS.h>// Media pins#define ledPin 13       // digital pin 13                          const int pin = 0; // analog pin 0int tempc = 0;int tempb = 0;char tempx [50];// Variableschar text [50];boolean state=0;TTS text2speech;  // speech output is digital pin 10void setup() {}void loop(){  // Takes 8 samples and sums upfor(int i = 0; i < 8; i++){tempc += analogRead(pin);}// Makes some calculationstempc = (5.0 * tempc * 100.0) / (8.0 * 1024.0);int tempb = tempc + 0.5;state = !state;Test_Speech();}void Test_Speech(){text2speech.setPitch(6); //lower values = higher voice pitchitoa (tempb, tempx, 10); // convert integer to stringstrcpy(text, tempx);text2speech.say(text);delay(500);}`

[size=18]Well, it compiles now![/size]

#### PaulS

#19
##### Aug 11, 2010, 04:08 pm
Quote
Well, it compiles now!

Does it work?

#### D3C3PT1C0N

#20
##### Aug 11, 2010, 04:40 pmLast Edit: Aug 11, 2010, 04:56 pm by Fredx Reason: 1
I didn't have a chance to try it before but now, when i uploaded and connected earphones + LM35 temp sensor, it is saying ERROR-ERROR-ERROR... in a voice

Code: [Select]
`void Test_Speech(){text2speech.setPitch(6); //lower values = higher voice pitchitoa (tempb, tempx, 10); // convert integer to stringstrcpy(text, tempx);text2speech.say(text);delay(500);}`

If i write:
Quote
itoa (tempb, tempx, 10); // convert integer to string
Serial.print(tempx);
strcpy(text, tempx);
text2speech.say(text);

Then it gives none in Serial Monitor

#### PaulS

#21
##### Aug 11, 2010, 07:34 pm
What does Serial.print(tempb); show?

Code: [Select]
`tempc = (5.0 * tempc * 100.0) / (8.0 * 1024.0);`
tempc is an int. What do you end up with in tempc?

Code: [Select]
`int tempb = tempc + 0.5;`
tempb is a local variable with the same name as a global variable. Adding 0.5 to an int does nothing.

The global tempb is never modified, Test_Speech() should be converting 0 to a string.

Code: [Select]
`strcpy(text, tempx);`
Why copy one array to another array of the same size?

#### D3C3PT1C0N

#22
##### Aug 12, 2010, 12:07 amLast Edit: Aug 12, 2010, 12:31 am by Fredx Reason: 1
It's actually working. It just has really bad sound quality that i didn't understand it. Numbers 0 - 9 are quite understandable, but 10 - .. are awful. Therefore i would like to know, if it is possible to make 23 to 2 3 (with space between)?
Quote

#include <TTS.h>
const int pin = 0; // analog pin 0
int tempc = 0;
char tempx [50];
boolean state=0;
TTS text2speech;  // speech output is digital pin 10

void setup()
{Serial.begin(9600);}

void loop()
{
for(int i = 0; i < 8; i++)
tempc = ((5.0 * tempc * 100.0) / (8.0 * 1024.0)) + 0.5;
state = !state;
Test_Speech();
}

void Test_Speech()
{
text2speech.setPitch(6); //lower values = higher voice pitch
itoa (tempc, tempx, 10); // convert integer to string
Serial.print(tempx);
text2speech.say(tempx);
delay(500);
}

#### D3C3PT1C0N

#23
##### Aug 12, 2010, 01:01 amLast Edit: Aug 12, 2010, 01:05 am by Fredx Reason: 1
Here is the [size=14]The Final Code[/size][/b] (fully working)

Code: [Select]
`#include <TTS.h>                          const int pin = 0; // analog pin 0int digit1 = 0;int digit2 = 0;int tempc = 0;char temp1 [1];char temp2 [1];boolean state=0;TTS text2speech;  // speech output is digital pin 10void setup(){Serial.begin(9600);}void loop(){ for(int i = 0; i < 8; i++){tempc += analogRead(pin);}tempc = (5.0 * tempc * 100.0) / (8.0 * 1024.0);digit1 = tempc / 10; // get the ten's digitdigit2 = tempc % 10; // get the one's digitstate = !state;Test_Speech();}void Test_Speech(){text2speech.setPitch(6); //lower values = higher voice pitchitoa (digit1, temp1, 10); // convert integer to stringtext2speech.say(temp1);delay(500);itoa (digit2, temp2, 10); // convert integer to stringtext2speech.say(temp2);delay(500);text2speech.say("degrees");delay(1000);}`

Quote

PC Speaker sound for 24'C: TWO FOUR DEGREES

Thanks again, PaulS !!!

#### PaulS

#24
##### Aug 12, 2010, 01:20 am
Before you get real happy with that code, I'm going to suggest some changes. The itoa function adds a NULL to the end of the string. So, if the value passed to it is a one digit number, two characters will be written to the array, in which you provide room for one of them. Something else is getting overwritten.

If you looked at the values in the array, you would see that 1 is converted to '1', 2 is converted to '2', etc.

You can do this much more efficiently:

Code: [Select]
`char temp1[2];char temp2[2];temp1[0] = digit1 + '0';temp1[1] = '\0'; // Add the NULL terminatortemp2[0] = digit2 + '0';temp2[1] = '\0';`

Try this in place of the calls to itoa, and see how much smaller your compiled code gets.

#### D3C3PT1C0N

#25
##### Aug 12, 2010, 01:32 amLast Edit: Aug 12, 2010, 01:37 am by Fredx Reason: 1
Thank you
Code smaller and still working.

#### Paulware

#26
##### Jan 21, 2011, 08:17 am
Ro-Bot-X -
Thank you so much!  Worked the first time!  Exactly what I was looking for!

I used my pc speakers to output since they had an amplifier.

By the way is there any way to increase the quality?  By using Phonics perhaps to sound out the word I want to hear?

Any updated releases?

Thanks again 8-)

#### Ro-Bot-X

#27
##### Jan 22, 2011, 12:45 amLast Edit: Jan 22, 2011, 12:55 am by Ro-Bot-X Reason: 1
Here is the list of phonemes, you can try to use them instead of text. You can also play with the intonation in the phonemes.

Code: [Select]
`Quoting original text by Webbot (Clive Webster):If you are programatically calling the speak method, or your text starts with a '*' character then the following text is made up of phonemes with optional pitch numbers. If you are just 'playing' then it is very likely that you may get an error message - because you have used a phoneme that is not in the following list. The valid phonemes are:-AY as in 'pale'AE as in 'black'AA as in 'car'AI as in 'fair'EE as in 'meet'EH as in 'get'ER as in 'perk'IY as in 'site'IX as in 'sit'IH as in 'sit!!'OW as in 'coat'O as in 'cot'UX as in 'coot'OY as in 'voice'AW as in 'now'AO as in 'door'OH as in 'won'UW as in 'you'/U as in 'put'UH as in 'wood'AH as in 'up'B as in 'bat'D as in 'dab'F as in 'fat'G as in 'gap'/H as in 'hat'J as in 'jab'K as in 'cat'L as in 'lag'M as in 'mat'N as in 'nap'P as in 'pat'R as in 'rat'S as in 'sat'T as in 'tap'V as in 'vat'W as in 'wag'Y as in 'yap'Z as in 'zap'CH as in 'chair'DH as in 'this'SH as in 'share'TH as in 'thick'ZH as in 'azure'CT as in 'fact'DR as in 'dragon'DUX as in 'duke'NX as in 'sing'TR as in 'track' When using phonemes you can optionally append a number from 1 to 8 to change the pitch of the phoneme.So to say 'Welcome everyone' using phonemes we could use 'WEH4LKAHM EH3VREEWON'`

Since I have no idea how this stuff works, I just converted it into a library, I can't improve it further. If anyone can do a better job, please do and post the code for others to use, as I did, with the permission of the original developer. Also, he said he did his best at it and can't be convinced to spend more time in this matter. He included his code to his WebbotLib library for building robots with AVR controllers.

Go Up

Please enter a valid email to subscribe