ESP32+TFTLCD实现WiFi天气语音播报(六)

ESP32+MY1680U实现语音播报

文章目录

前言

在这一章将实现MY1680U语音模块播放MP3,语音播报存入的语句。
需要用到的资料 提取码:lwm2

一、MY1680U-12P 语音模块

1、概述

MY1680U-12P 是深圳市迈优科技有限公司自主研发的一款小巧的集成MP3模块。采用MY1680U-16S MP3主控芯 片,支持MP3、WAV格式双解码,模拟U盘下载。模块内置FLASH存储芯片,1-16M容量可选;也可外接U盘或USB数据线连接电脑更换FLASH的音频文件。该模块内置3W功放,可以直接驱动3W的喇叭,使用更方便。

产品特性

  • 支持 MP3 、WAV 高品质音频格式文件,声音优美。
  • 24 位 DAC 输出,动态范围支持 93dB,信噪比支持 85dB。
  • 完全支持 FAT16、FAT32 文件系统,最大支持 16M FLASH,32G 的 U 盘。
  • 支持 UART 异步串口控制:支持播放、暂停、上下曲、音量加减、选曲播放、插播等。
  • ADKEY 功能,通过电阻选择可实现标准 MP3 功能的 5 按键控制和其他功能。
  • 内置音量、曲目掉电记忆功能。  支持 USB 连接电脑下载声音。
  • 自带 3W 的功放,直接外接喇叭即可完成播放;音量不够客户也可外接功放。
  • MY1690-12P 插 SD 卡模块与这款管脚兼容,需要升级大存储空间方便更换

2、参数说明

ESP32+TFTLCD实现WiFi天气语音播报(六)
ESP32+TFTLCD实现WiFi天气语音播报(六)
MY1680U-12P内置标准UART异步串口接口,为3.3V TTL电平接口,波特率9600。可通过MAX3232芯片转换成RS232电平或者通过 USB转TTL模块与PC通讯进行调试。通讯数据格式是:
起始位:1位;数据位:8位;奇偶位:无;停止位:1位。
向语音模块里面传入音频文件可以通过USB连接电脑传输也可以通过USB转TTL模块,使用电脑串口调试助手,传输音频文件
USB转TTL模块与MY1680U-12P的连接图
ESP32+TFTLCD实现WiFi天气语音播报(六)
这里是串口调试助手的下载地址 提取码:lwm2
;

使用普通的Android手机数据线连接模块,第一次连接就会自动安装驱动程序。安装成功后,计算机可以弹出可移动磁盘,直接命名声音,然后将其拖动到磁盘中。
[En]

Using the ordinary Android phone data cable connection module, the driver will be installed automatically the first time you connect. After the installation is successful, the computer can eject the removable disk, name the sound directly, and then drag it into the disk.

ESP32+TFTLCD实现WiFi天气语音播报(六)

照歌曲命名规则

  • 存根目录的命名方式如下:以四位数字开头,后接中文或非中文。
    [En]

    the stub directory is named in the following way, starting with four digits, followed by Chinese or not.*

  • 创建文件夹时,文件夹按以下方式命名,文件夹以两位数开头,文件夹中的歌曲以三位数命名,后跟中文或非中文。
    [En]

    when creating a folder, the folder is named in the following way, the folder begins with two digits, and the songs in the folder are named with three digits followed by Chinese or not.*

朗读女 提取码:lwm2
这个软件可以把你输入的文字合成成音频文件。

[En]

This software can synthesize the text you enter into audio files.

二、代码实现

1.MY1690.c

代码如下:

#include "MY1690.h"

VOICE_DEV voice1={.frame_head = 0x7E,.frame_end = 0xEF};

u8 Voice_Table[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21};

void MY1690_UARTConfig(u32 brr)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    USART_InitTypeDef USART_InitStructure;

    RCC_APB2PeriphClockCmd(MY1690_TX_CLK | MY1690_RX_CLK, ENABLE);
    MY1690_UART_CLKCMD(MY1690_UART_CLK, ENABLE);

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Pin = MY1690_TX_PIN;
    GPIO_Init(MY1690_TX_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_InitStructure.GPIO_Pin = MY1690_RX_PIN;
    GPIO_Init(MY1690_RX_PORT, &GPIO_InitStructure);

    USART_InitStructure.USART_BaudRate = brr;
    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
    USART_InitStructure.USART_Parity = USART_Parity_No;
    USART_InitStructure.USART_StopBits = USART_StopBits_1;
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_Init(MY1690_USART, &USART_InitStructure);
    USART_Cmd(MY1690_USART,ENABLE);
}

void MY1690_SendString(u8 *str,u8 lenth)
{
    for(u8 i=0; i<lenth; i++)
    {
        while(USART_GetFlagStatus(MY1690_USART,USART_FLAG_TC) == RESET);
        USART_SendData(MY1690_USART, str[i]);
    }
}

void MY1690_Init(void)
{

    GPIO_InitTypeDef GPIO_InitStructure;
    RCC_APB2PeriphClockCmd(MY1690_BUSY_CLK, ENABLE);
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Pin = MY1690_BUSY_PIN;
    GPIO_Init(MY1690_BUSY_PORT, &GPIO_InitStructure);

    MY1690_UARTConfig(9600);
    Voice_SendCmd(0x38,0x01,0x00,1);
}

u8 Voice_XorCheck(u8 *pdata,u8 lenth)
{
    u8 r_value = *pdata;
    u8 i = 0;
    for(i=1;i<lenth;i++)
    {
        r_value ^= pdata[i];
    }
    return r_value;
}

void Voice_SendCmd(u8 cmd,u8 arg1,u8 arg2,u8 arg_lenth)
{

    voice1.cmd = cmd;

    voice1.arg[0] = arg1;
    voice1.arg[1] = arg2;
    voice1.arg[2] = arg_lenth;

    voice1.lenth = 3+arg_lenth;
    voice1.xorcheck = Voice_XorCheck(&voice1.lenth,2+arg_lenth);

    MY1690_SendString(&voice1.frame_head,3);
    MY1690_SendString(voice1.arg,arg_lenth);
    MY1690_SendString(&voice1.xorcheck,2);
}

void Voice_PlayDirectoryMusic(u8 directorynum, u8 musicnum)
{
    while(VoicePlay_Busy);
    Voice_SendCmd(CMD_CHOOSE_MUSIC,directorynum,musicnum,2);
}

2.MY1690.h

代码如下:

#ifndef _MY1690_H_
#define _MY1690_H_

#include "stm32f10x.h"
#include "stdio.h"

#define MY1690_USART                    USART2
#define MY1690_UART_CLKCMD      RCC_APB1PeriphClockCmd
#define MY1690_UART_CLK             RCC_APB1Periph_USART2

#define MY1690_TX_CLK                   RCC_APB2Periph_GPIOA
#define MY1690_TX_PORT              GPIOA
#define MY1690_TX_PIN                   GPIO_Pin_2

#define MY1690_RX_CLK                   RCC_APB2Periph_GPIOA
#define MY1690_RX_PORT              GPIOA
#define MY1690_RX_PIN                   GPIO_Pin_3

#define MY1690_BUSY_CLK             RCC_APB2Periph_GPIOB
#define MY1690_BUSY_PORT            GPIOB
#define MY1690_BUSY_PIN             GPIO_Pin_6

#define CMD_PLAY                0x11
#define CMD_STOP                0x12
#define CMD_NEXT                0x13
#define CMD_PREV                    0x14
#define CMD_VOICEADD        0x15
#define CMD_VOICESUB        0x16
#define CMD_RESET           0x19
#define CMD_SPEED           0x1A
#define CMD_SLOW            0x1B
#define CMD_STARTorSTOP     0x1C
#define CMD_END             0x1E
#define CMD_ROOTCHO_MUSIC 0x41
#define CMD_CHOOSE_MUSIC    0x42

typedef struct
{
    u8 frame_head;
    u8 lenth;
    u8 cmd;
    u8 arg[3];
    u8 xorcheck;
    u8 frame_end;
}VOICE_DEV;

#define VoicePlay_Busy  GPIO_ReadInputDataBit(MY1690_BUSY_PORT, MY1690_BUSY_PIN)

#define POS_SHI             10
#define POS_HUNDRED     11
#define POS_THOUSAND    12
#define POS_WAN             13
#define POS_START           14
#define POS_RESULT      15
#define POS_OK              16
#define POS_ERR             17
#define POS_NODRINK     18
#define POS_DRINK           19
#define POS_WELCOME     20

extern u8 Voice_Table[];

void MY1690_UARTConfig(u32 brr);
void MY1690_Init(void);
void MY1690_SendString(u8 *str,u8 lenth);
u8 Voice_XorCheck(u8 *pdata,u8 lenth);
void Voice_SendCmd(u8 cmd,u8 arg1,u8 arg2,u8 arg_lenth);
void Voice_PlayDirectoryMusic(u8 directorynum, u8 musicnum);
void Voice_PlayNumber(u16 number);
#endif

3.main.c

#include "main.h"
#include "delay.h"
#include "led.h"
#include "key.h"
#include "beep.h"
#include "lcd.h"
#include "rose.h"
#include "leaf.h"
#include "bridge.h"
#include "MY1690.h"

int main(void)
{
    JTAG_SWD_Config();
    SysTick_Init(72000);
    Led_Config();
    Beep_Config();
    Key_Config();
    LCD_Init();
    MY1690_Init();

    Voice_PlayDirectoryMusic(03,010);
    while(1)
    {

    }
}

用到的音频文件 提取码:lwm2

总结

MY1680U语音模块播放歌曲差不多哦就这么多内容。

Original: https://blog.csdn.net/qq_44890147/article/details/121321631
Author: 清道 夫
Title: ESP32+TFTLCD实现WiFi天气语音播报(六)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/526793/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球