【Arduino】实验使用OPT语音模块播放语音(图文)

当我们需要在程序中播放语音内容时,就需要使用到语音模块,今天我们就来实验一下使用OPT语音模块来方法语音。

const int voicePin     = 5;
const int voiceBusyPin = 18;
const int testLEDPin   = 2;

unsigned long pmillis = 0;

int busyVal = 0;                  // 默认高-空闲

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(voicePin, OUTPUT);
  pinMode(voiceBusyPin, INPUT);
  pinMode(testLEDPin, OUTPUT);
  digitalWrite(voicePin , HIGH);  
  delay(300);

  digitalWrite(testLEDPin , HIGH);  

  // 组合语音播放 方法二
  CVPlay(8,     74, 34, 36, 29,  39, 34, 40, 61);          //设置播放语音内容
  delay(10000);
  sendData(0xFE); // 停止播放
  delay(50);
}

void loop() {
  // put your main code here, to run repeatedly:
}

// 发送数据-无起始位
void cSendData(int addr) {
  for (int i = 0; i < 8; i++) {
    digitalWrite(voicePin, HIGH);
    if (addr & 1) {
      delayMicroseconds(2400); // >2400us
      digitalWrite(voicePin, LOW);
      delayMicroseconds(800);  // >800us
    } else {
      delayMicroseconds(800);  // >800us
      digitalWrite(voicePin , LOW);
      delayMicroseconds(2400); // >2400us
    }
    addr >>= 1;
  }
  digitalWrite(voicePin, HIGH);
}


void CVPlay(byte cNotes, ...) {
  va_list ap;
  unsigned int uAddr;
  int checksum = 0;
  va_start(ap, cNotes);
  while (cNotes > 0 ) {
    Serial.println(cNotes);
    uAddr = va_arg(ap, unsigned int);
    sendData(uAddr);
    delay(100);
    while (!digitalRead(voiceBusyPin)) {}  // busy信号低 - 忙
    cNotes--;
  }
  va_end(ap);
}

这里使用OPT语音模块,模块中内置里一些语音文字,通过使用文字组合提前设置好写到程序中,即可播放自己需要的语音内容。需要使用的文字根据模块提供的词语表进行对照。

OPT模块有4个针脚,其中2个是电源,另外一个数据,一个是busy。

接通好电路后,编译上传后即可听到设置的语音内容:“现在时刻:12:56分。”

通过以上实验,我们可以知道使用OPT模块可以进行语音播报,但是这个需要播放的内容是需要提前知道并且设置到程序中,而比如想要播放一个变量时则这种方法就不行了,后续我们再继续研究。 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小飞鱼通达二开

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值