Foreword
The voice module is one of the common modules in our learning projects. Today I will share with you the simple use of the SYN6288 module. For the software part, I will provide the complete code of stm32f103zet6/stm32f407zgt6 for your reference. For in-depth study, you also need to carefully read data sheets and other materials. Hope this article can help everyone!
1. Introduction to SYN6288 speech synthesis module
The SYN6288 speech synthesis module is a speech synthesis module based on DSP technology, which can convert text information into natural and smooth speech output. This module has the following features:
1. Supports multiple languages, including Chinese, English, Japanese, etc.
2. Volume, speaking speed, pitch and other parameters can be adjusted to meet different needs.
3. Using digital speech synthesis technology, the output speech is clear and natural.
4. Supports serial port communication, easy to use.
5. Small size and low power consumption, suitable for various speech synthesis application scenarios.
SYN6288 speech synthesis module is widely used in smart homes, smart robots, smart interactive devices, voice prompt systems and other fields.
2. Hardware preparation
1. Hardware materials
SYN6288 module, STM32F103/STM32F407 (other development boards can also be used, here are required for demonstration), DuPont line
2. Hardware connection
stm32 | syn6288 |
5V | VCC |
TX | RXD |
RX | TXD |
GND | GND |
PS: This time we use PA9 and PA10 of USART1 as TX and RX
3. Physical picture of hardware
3. Software code (here, take the stm32f407 program as an example)
1. New project
For questions related to new projects, please read my article STM32 – New Project Template Based on Firmware Library
At this time, I usually create a new include.h file in the USER folder to reference the header files required by all projects;
Create a new HARDWARE folder specifically to store syn6288 related programs.
2. Serial communication
(1) Serial port initialization (we use USART1 here, other serial ports can also be used)
/*Initialize USART1*/ void uart_init(u32 bound) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; \t RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); //Enable GPIOA clock RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);//Enable USART1 clock //Serial port 1 corresponding pin multiplexing mapping GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1); //GPIOA9 is reused as USART1 GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1); //GPIOA10 is reused as USART1 \t //USART1 port configuration GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; //GPIOA9 and GPIOA10 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//Multiplex function GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //Speed 50MHz GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //Push-pull multiplexing output GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //Pull-up GPIO_Init(GPIOA, & amp;GPIO_InitStructure); //Initialize PA9, PA10 //USART1 initialization settings USART_InitStructure.USART_BaudRate = bound;//Baud rate setting USART_InitStructure.USART_WordLength = USART_WordLength_8b;//The word length is 8-bit data format USART_InitStructure.USART_StopBits = USART_StopBits_1;//A stop bit USART_InitStructure.USART_Parity = USART_Parity_No;//No parity bit USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//No hardware data flow control USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //Transceiver mode USART_Init(USART1, & amp;USART_InitStructure); //Initialize serial port 1 \t USART_Cmd(USART1, ENABLE); //Enable serial port 1 \t //USART_ClearFlag(USART1, USART_FLAG_TC); \t \t USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//Enable related interrupts //Usart1 NVIC configuration NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;//Serial port 1 interrupt channel NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;//Preemption priority 3 NVIC_InitStructure.NVIC_IRQChannelSubPriority =3; //Sub priority 3 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ channel enable NVIC_Init( & amp;NVIC_InitStructure); //Initialize the VIC register according to the specified parameters. }
(2) Serial port interrupt function
/*Serial port 1 interrupt service routine*/ void USART1_IRQHandler(void) { u8 Res; if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //Receive interrupt (received data must end with 0x0d 0x0a) { Res = USART_ReceiveData(USART1); //Read the received data \t\t if((USART_RX_STA & amp; 0x8000) == 0) //reception is not completed { if(USART_RX_STA < USART_REC_LEN) //Can also receive data { USART_RX_BUF[USART_RX_STA + + ] = Res; //Record the received value } else { USART_RX_STA |= 1 << 15; //Force mark reception completed } } } }
(3) Send data
void Usart_SendData(u8 data) { while((USART1->SR & amp; 0X40) == 0); USART1->DR = data; } void USART1_SendString(u8 *DAT, u8 len) { u8i; for(i = 0; i < len; i + + ) { Usart_SendData(*DAT + + ); } }
(4) Specific codes for serial communication, most of which have been shown above
3.SYN6288 code
(1) The main code is as follows
Here we only introduce how to use it simply. If you need to study in depth, please read the data sheet and other materials.
//Select background music 2. (0: No background music 1-15: Background music optional) //m[0~16]:0 background music is mute, 16 background music volume is the largest //v[0~16]: 0 reading volume is mute, 16 reading volume is the maximum //t[0~5]: 0 reads at the slowest speed, 5 reads at the fastest speed //For other uncommon functions, please refer to the data sheet. void SYN_FrameInfo(u8 *HZdata) { /******************Text to be sent********************************** *****/ unsigned char Frame_Info[50]; unsigned char HZ_Length; unsigned char ecc = 0; //Define check byte unsigned int i = 0; HZ_Length = strlen((char*)HZdata); //The length of the text that needs to be sent /************************Frame fixed configuration information**************************** **********/ Frame_Info[0] = 0xFD; //Construct frame header FD Frame_Info[1] = 0x00; //Construct the high byte of the data area length Frame_Info[2] = HZ_Length + 3; //Construct the low byte of the data area length Frame_Info[3] = 0x01; //Construct command word: synthesize playback command Frame_Info[4] = 0x01 | 0 << 4; //Construction command parameters: background music setting /************************Check code calculation**************************** *************/ for(i = 0; i < 5; i + + ) //Send the constructed 5 frame header bytes in sequence { ecc = ecc ^ (Frame_Info[i]); //Exclusive OR check on the sent bytes } for(i = 0; i < HZ_Length; i + + ) //Send the text data to be synthesized in sequence { ecc = ecc ^ (HZdata[i]); //Exclusive OR check on the sent bytes } /************************Send frame information****************************** ************/ memcpy(&Frame_Info[5], HZdata, HZ_Length); Frame_Info[5 + HZ_Length] = ecc; USART1_SendString(Frame_Info, 5 + HZ_Length + 1); }
/********************************************** ************* * Name: YS_SYN_Set(u8 *Info_data) * Function: Main function program entry * Entry parameters: *Info_data: Fixed configuration information variable * Export parameters: * Description: This function is used for configuration, stop synthesis, pause synthesis and other settings. The default baud rate is 9600bps. * Calling method: configure by calling the defined related array. *************************************************** **********/ void YS_SYN_Set(u8 *Info_data) { u8 Com_Len; Com_Len = strlen((char*)Info_data); USART1_SendString(Info_data, Com_Len); }
(2) The overall code is as follows
4. Main function program
(1) Reference header file
Note that the speaker module needs to reference string.h
(2) Call the syn6288 function in main.c
Finally burn Just run the recording program!
4. stm32f103 program reference
There is no difference in the syn6288 code, only the initialization of usart needs to be modified, and the specific needs to be slightly adjusted according to the situation!
The general code is as follows:
I hope my article can help everyone. If you need relevant information and programs, please feel free to send a private message. I am happy to open source them. If there are any problems with the article, I hope you will bear with me and give me some suggestions.