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


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

    1. const int voicePin = 5;
    2. const int voiceBusyPin = 18;
    3. const int testLEDPin = 2;
    4. unsigned long pmillis = 0;
    5. int busyVal = 0; // 默认高-空闲
    6. void setup() {
    7. // put your setup code here, to run once:
    8. Serial.begin(9600);
    9. pinMode(voicePin, OUTPUT);
    10. pinMode(voiceBusyPin, INPUT);
    11. pinMode(testLEDPin, OUTPUT);
    12. digitalWrite(voicePin , HIGH);
    13. delay(300);
    14. digitalWrite(testLEDPin , HIGH);
    15. // 组合语音播放 方法二
    16. CVPlay(8, 74, 34, 36, 29, 39, 34, 40, 61); //设置播放语音内容
    17. delay(10000);
    18. sendData(0xFE); // 停止播放
    19. delay(50);
    20. }
    21. void loop() {
    22. // put your main code here, to run repeatedly:
    23. }
    24. // 发送数据-无起始位
    25. void cSendData(int addr) {
    26. for (int i = 0; i < 8; i++) {
    27. digitalWrite(voicePin, HIGH);
    28. if (addr & 1) {
    29. delayMicroseconds(2400); // >2400us
    30. digitalWrite(voicePin, LOW);
    31. delayMicroseconds(800); // >800us
    32. } else {
    33. delayMicroseconds(800); // >800us
    34. digitalWrite(voicePin , LOW);
    35. delayMicroseconds(2400); // >2400us
    36. }
    37. addr >>= 1;
    38. }
    39. digitalWrite(voicePin, HIGH);
    40. }
    41. void CVPlay(byte cNotes, ...) {
    42. va_list ap;
    43. unsigned int uAddr;
    44. int checksum = 0;
    45. va_start(ap, cNotes);
    46. while (cNotes > 0 ) {
    47. Serial.println(cNotes);
    48. uAddr = va_arg(ap, unsigned int);
    49. sendData(uAddr);
    50. delay(100);
    51. while (!digitalRead(voiceBusyPin)) {} // busy信号低 -
    52. cNotes--;
    53. }
    54. va_end(ap);
    55. }

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

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

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

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

  • 相关阅读:
    『现学现忘』Git分支 — 40、分支基本操作(一)
    Android 9.0 隐藏设置中一级菜单“已连接的设备”
    【PyQt】PyQt入门安装和Hello World
    Java中23种设计模式-单例模式--工厂模式
    前端开箱即用的中后台管理模版,建议收藏
    window电脑关闭docker中正在运行redis的 RDB 和AOF 持久化选项
    Z41H-64C高压闸阀型号解析
    『Echarts』基本使用
    【Mysql】模糊查询
    车云汇元宇宙:开启虚拟与现实融合的汽车养护新篇章
  • 原文地址:https://blog.csdn.net/upi2u/article/details/139726298