Europe, Estonia
Offline
Full Member
Karma: 0
Posts: 208
|
 |
« Reply #15 on: June 27, 2010, 08:55:26 am » |
I did some changes void loop() {
// Takes 8 samples and sums up for(int i = 0; i < 8; i++) { tempc += analogRead(pin); }
// 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, 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 ?
|
|
|
|
« Last Edit: June 27, 2010, 10:21:54 am by Fredx »
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #16 on: July 03, 2010, 08:07:10 am » |
int tempb = tempc + 0.5; This statement, in loop, creates a local variable, named tempb, and assigns it a value. 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.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #17 on: August 10, 2010, 08:24:47 am » |
No idea what to do.. The IDE told you which line caused the error. I'm guessing it was this one: 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.
|
|
|
|
|
Logged
|
|
|
|
|
Europe, Estonia
Offline
Full Member
Karma: 0
Posts: 208
|
 |
« Reply #18 on: August 11, 2010, 08:15:40 am » |
I had mistakes in previous code. Here is the current script i'm working on: /* The Text To Speech library uses Timer1 to generate the PWM output on digital pin 10. The output signal needs to be fed to 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 0
int tempc = 0; int tempb = 0; char tempx [50];
// Variables char text [50]; boolean state=0;
TTS text2speech; // speech output is digital pin 10
void setup() {}
void loop() {
// Takes 8 samples and sums up for(int i = 0; i < 8; i++) { tempc += analogRead(pin); }
// 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); // convert integer to string strcpy(text, tempx); text2speech.say(text); delay(500); }
[size=18]Well, it compiles now![/size]
|
|
|
|
« Last Edit: August 11, 2010, 09:30:51 am by Fredx »
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #19 on: August 11, 2010, 09:08:57 am » |
Well, it compiles now! Does it work?
|
|
|
|
|
Logged
|
|
|
|
|
Europe, Estonia
Offline
Full Member
Karma: 0
Posts: 208
|
 |
« Reply #20 on: August 11, 2010, 09:40:50 am » |
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  void Test_Speech() { text2speech.setPitch(6); //lower values = higher voice pitch itoa (tempb, tempx, 10); // convert integer to string strcpy(text, tempx); text2speech.say(text); delay(500); } If i write: itoa (tempb, tempx, 10); // convert integer to string Serial.print(tempx); strcpy(text, tempx); text2speech.say(text); Then it gives none in Serial Monitor
|
|
|
|
« Last Edit: August 11, 2010, 09:56:20 am by Fredx »
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #21 on: August 11, 2010, 12:34:58 pm » |
What does Serial.print(tempb); show? tempc = (5.0 * tempc * 100.0) / (8.0 * 1024.0); tempc is an int. What do you end up with in tempc? 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. strcpy(text, tempx); Why copy one array to another array of the same size?
|
|
|
|
|
Logged
|
|
|
|
|
Europe, Estonia
Offline
Full Member
Karma: 0
Posts: 208
|
 |
« Reply #22 on: August 11, 2010, 05:07:45 pm » |
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)? #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 += analogRead(pin);} 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); }
|
|
|
|
« Last Edit: August 11, 2010, 05:31:52 pm by Fredx »
|
Logged
|
|
|
|
|
Europe, Estonia
Offline
Full Member
Karma: 0
Posts: 208
|
 |
« Reply #23 on: August 11, 2010, 06:01:39 pm » |
Here is the [size=14]The Final Code[/size][/b] (fully working) #include <TTS.h> const int pin = 0; // analog pin 0 int digit1 = 0; int digit2 = 0; int tempc = 0; char temp1 [1]; char temp2 [1]; 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 += analogRead(pin);} tempc = (5.0 * tempc * 100.0) / (8.0 * 1024.0); digit1 = tempc / 10; // get the ten's digit digit2 = tempc % 10; // get the one's digit state = !state; Test_Speech(); }
void Test_Speech() { text2speech.setPitch(6); //lower values = higher voice pitch itoa (digit1, temp1, 10); // convert integer to string text2speech.say(temp1); delay(500); itoa (digit2, temp2, 10); // convert integer to string text2speech.say(temp2); delay(500); text2speech.say("degrees"); delay(1000); }
PC Speaker sound for 24'C: TWO FOUR DEGREES
Thanks again, PaulS !!!
|
|
|
|
« Last Edit: August 11, 2010, 06:05:03 pm by Fredx »
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #24 on: August 11, 2010, 06:20:26 pm » |
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: char temp1[2]; char temp2[2]; temp1[0] = digit1 + '0'; temp1[1] = '\0'; // Add the NULL terminator temp2[0] = digit2 + '0'; temp2[1] = '\0'; Try this in place of the calls to itoa, and see how much smaller your compiled code gets.
|
|
|
|
|
Logged
|
|
|
|
|
Europe, Estonia
Offline
Full Member
Karma: 0
Posts: 208
|
 |
« Reply #25 on: August 11, 2010, 06:32:46 pm » |
Thank you Code smaller and still working.
|
|
|
|
« Last Edit: August 11, 2010, 06:37:56 pm by Fredx »
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 2
Posts: 115
Arduino rocks
|
 |
« Reply #26 on: January 21, 2011, 02:17:58 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-)
|
|
|
|
|
Logged
|
|
|
|
|
Toronto, Canada
Offline
Full Member
Karma: 0
Posts: 144
Arduino rocks
|
 |
« Reply #27 on: January 21, 2011, 06:45:36 pm » |
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. 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.
|
|
|
|
« Last Edit: January 21, 2011, 06:55:39 pm by Ro-Bot-X »
|
Logged
|
|
|
|
|
|