|
Arduino2560和Syn6628语音芯片做语音播报系统,loop程序不严密,怎么修改程序结构?
关于程序结构的求助。
第一次接触Arduino,想要结合Syn6628语音芯片,做一个语音播报系统。
其中播放的 语音子函数speech(1,2,3,4) 是由Arduino_LPTTS函数生成器生成。通过按一个键
输出一个相应的语音。现在的问题是
loop函数中该怎么调用speech(1,2,3,4),我写的程序太简单,有一些有问题。当正播放一个语音时,按下另一个按键以播放另一句语音时,有6、7秒的反应时间,而且有时会进入死循环。该怎么修改程序结构解决这些问题,请各位高手指教。
程序如下:
int key1=4;//按下该键播放语音语音1
int key2=5;//按下该键播放语音语音2
int key3=6;//按下该键播放语音语音3
int key4=7;//按下该键播放语音语音4
int state1=0;
int state2=0;
int state3=0;
int state4=0;
//语音子函数speech(1,2,3,4) 是由Arduino_LPTTS函数生成器自动生成
//1、黄绮珊 剪爱
void speech1()
{
unsigned char i = 0;
unsigned char head[18];
head[0] = 0xFD;
head[1] = 0x00;
head[2] = 0x0F;
head[3] = 0x01;
head[4] = 0x08;
head[5] = 0xBB;
head[6] = 0xC6;
head[7] = 0xE7;
head[8] = 0xB2;
head[9] = 0xC9;
head[10] = 0xBA;
head[11] = 0x20;
head[12] = 0x20;
head[13] = 0xBC;
head[14] = 0xF4;
head[15] = 0xB0;
head[16] = 0xAE;
head[17] = 0xF6;
for(i=0; i<18; i++){
Serial.write(head[i]);
}
}
//2、我们都是
void speech2()
{
unsigned char i = 0;
unsigned char head[38];
head[0] = 0xFD;
head[1] = 0x00;
head[2] = 0x23;
head[3] = 0x01;
head[4] = 0x08;
head[5] = 0xCE;
head[6] = 0xD2;
head[7] = 0xC3;
head[8] = 0xC7;
head[9] = 0xB6;
head[10] = 0xBC;
head[11] = 0xCA;
head[12] = 0xC7;
head[13] = 0xBA;
head[14] = 0xC3;
head[15] = 0xBA;
head[16] = 0xA2;
head[17] = 0xD7;
head[18] = 0xD3;
head[19] = 0xA3;
head[20] = 0xAC;
head[21] = 0xCA;
head[22] = 0xB7;
head[23] = 0xC9;
head[24] = 0xCF;
head[25] = 0xD7;
head[26] = 0xEE;
head[27] = 0xC9;
head[28] = 0xC6;
head[29] = 0xC1;
head[30] = 0xBC;
head[31] = 0xB5;
head[32] = 0xC4;
head[33] = 0xBA;
head[34] = 0xA2;
head[35] = 0xD7;
head[36] = 0xD3;
head[37] = 0xFF;
for(i=0; i<38; i++){
Serial.write(head[i]);
}
}
//3、请关闭电源,锁好门窗
void speech3(){
unsigned char i = 0;
unsigned char head[26];
head[0] = 0xFD;
head[1] = 0x00;
head[2] = 0x17;
head[3] = 0x01;
head[4] = 0x00;
head[5] = 0xC7;
head[6] = 0xEB;
head[7] = 0xB9;
head[8] = 0xD8;
head[9] = 0xB1;
head[10] = 0xD5;
head[11] = 0xB5;
head[12] = 0xE7;
head[13] = 0xD4;
head[14] = 0xB4;
head[15] = 0xA3;
head[16] = 0xAC;
head[17] = 0xCB;
head[18] = 0xF8;
head[19] = 0xBA;
head[20] = 0xC3;
head[21] = 0xC3;
head[22] = 0xC5;
head[23] = 0xB4;
head[24] = 0xB0;
head[25] = 0xB7;
for(i=0; i<26; i++){
Serial.write(head[i]);
}
}
//4、一帆风顺,一路平安
void speech4()
{
unsigned char i = 0;
unsigned char head[24];
head[0] = 0xFD;
head[1] = 0x00;
head[2] = 0x15;
head[3] = 0x01;
head[4] = 0x50;
head[5] = 0xD2;
head[6] = 0xBB;
head[7] = 0xB7;
head[8] = 0xAB;
head[9] = 0xB7;
head[10] = 0xE7;
head[11] = 0xCB;
head[12] = 0xB3;
head[13] = 0xA3;
head[14] = 0xAC;
head[15] = 0xD2;
head[16] = 0xBB;
head[17] = 0xC2;
head[18] = 0xB7;
head[19] = 0xC6;
head[20] = 0xBD;
head[21] = 0xB0;
head[22] = 0xB2;
head[23] = 0x8E;
for(i=0; i<24; i++){
Serial.write(head[i]);
}
}
void setup()
{
Serial.begin(9600);
pinMode(key1,INPUT);
pinMode(key2,INPUT);
pinMode(key3,INPUT);
pinMode(key4,INPUT);
}
void loop()
{
state1=digitalRead(key1);
if(state1==HIGH)
{
delay(20);//延时去斗
state1=digitalRead(key1);
if(state1==HIGH)
speech1();
}
state2=digitalRead(key2);
if(state2==HIGH)
{
delay(20);
state2=digitalRead(key2);
if(state2==HIGH)
speech2();
}
state3=digitalRead(key3);
if(state3==HIGH)
{
delay(20);
state3=digitalRead(key3);
if(state3==HIGH)
speech3();
}
state4=digitalRead(key4);
if(state4==HIGH)
{
delay(20);
state4=digitalRead(key4);
if(state4==HIGH)
speech4();
}
}
|
|