SYN6288 voice broadcast module driver experiment based on STM32 (code open source)

Preface: This article is a hands-on teaching  of the driving experiment of the SYN6288 voice broadcast module. The  MCU  of this tutorial uses STM32F103ZET6 . Configure the UART serial port protocol through  CubeMX  software to drive the SYN6288 module to perform the specified voice broadcast. Considering  the high level of integration and intelligence of the SYN6288 module, the use of this module is extremely convenient. ( The code at the end of the article is open source! )

Hardware equipment: STM32F103ZET6; SYN6288;

Hardware physical map:

Renderings:

Pin connection:

SYN6288 pins:

RX --> PA2

TX --> PA3

VCC --> 5V

GND --> GND

1. Overview of SYN6288

SYN6288 Chinese speech synthesis chip is a high-end speech synthesis chip with higher cost performance and more natural effect launched by Beijing Yuyin Tianxia Technology Co., Ltd. in early 2010. SYN6288 receives the text data to be synthesized through the asynchronous serial port ( UART ) communication method, and realizes the conversion from text to speech (or TTS speech).

Yuyin Tianxia first developed the first speech synthesis chip OSYNO6188 in China in 2002 . The company's latest SYN6288 voice synthesis chip inherits the excellent features of the OSYNO6188 voice chip: the smallest SSOP28L patch package, simple hardware interface, low power consumption, clear and mellow timbre, and high cost performance; in addition, SYN6288 It is smarter and more accurate in recognizing text/numbers/strings, and the speech synthesis is more natural and intelligible. SYN6288 speech synthesis effect and intelligent level have been greatly improved, it is a Chinese speech synthesis chip that is really oriented to the application field of middle and high-end industries.

The birth of SYN6288 speech synthesis chip will promote the industry application of TTS speech synthesis technology to go deeper and wider!

2. The core narrative of SYN6288

1. The default baud rate of SYN6288 is: 9600, output string text to the module, and the module automatically outputs voice; ;

2. Prefixes can be added to the output character text (control parameters, volume and speech rate, etc.) to achieve more natural reading.

3. The chip supports the synthesis of any Chinese text, and can adopt four encoding methods of GB2312, GBK, BIG5 and Unicode. The chip supports the synthesis of English letters, and when encountering English words, it will be pronounced in alphabetical form. The amount of text synthesized each time can reach 200 bytes

4. The chip has the function of intelligent text analysis and processing. For texts in common formats such as numerical values, telephone numbers, time and date, and weight and measure symbols, the chip can correctly identify and process text according to the built-in text matching rules. For example: "2008-12-21" is read as "December 21, 2008", "10:36:28" is read as "10:36:28", "28 "℃" is read as "twenty-eight degrees Celsius" and so on. 

3. System composition

The minimum system includes: controller module, SYN6288 speech synthesis chip, power amplifier module and speakers.

The main controller ( MCU ) and the SYN6288 speech synthesis chip are connected through the UART interface. The controller can send control commands and texts to the SYN6288 speech synthesis chip through the communication interface. The SYN6288 speech synthesis chip synthesizes the received text into a speech signal output. The output signal is amplified by the power amplifier and then connected to the speaker for playback.

SYN6288 provides a set of full-duplex asynchronous serial communication ( UART ) interface to realize data transmission with microprocessor or PC . SYN 6288 uses TxD , RxD and GND to realize serial communication. Among them, GND is used as the ground signal. The SYN6288 chip supports the UART interface communication mode, and receives the commands and data sent by the host computer through the UART interface, and the maximum length of the data allowed to be sent is 206 bytes.

Four, CubeMX configuration

1. RCC is configured with an external high-speed crystal oscillator (higher precision) - HSE;

2. SYS configuration: Debug is set to Serial Wire ( otherwise it may cause the chip to self-lock );

3. USART2 configuration: asynchronous communication UART driver SYN6288, baud rate: 9600;

4. Clock tree configuration

5. Engineering configuration

Five, code and analysis

5.1 SYN6288 code

syn6288.h:

#ifndef __SYN6288_H
#define __SYN6288_H
 
#include "stm32f1xx_hal.h"
void SYN_FrameInfo(uint8_t Music, uint8_t *HZdata);
void YS_SYN_Set(uint8_t *Info_data);
 
#endif

syn6288.c:

#include "syn6288.h"
#include "usart.h"
#include "string.h"
 
//Music:选择背景音乐。0:无背景音乐,1~15:选择背景音乐
void SYN_FrameInfo(uint8_t Music, uint8_t *HZdata)
{
  /****************需要发送的文本**********************************/
  unsigned  char  Frame_Info[50];
  unsigned  char  HZ_Length;
  unsigned  char  ecc  = 0;  			//定义校验字节
  unsigned  int i = 0;
  HZ_Length = strlen((char*)HZdata); 			//需要发送文本的长度
 
  /*****************帧固定配置信息**************************************/
  Frame_Info[0] = 0xFD ; 			//构造帧头FD
  Frame_Info[1] = 0x00 ; 			//构造数据区长度的高字节
  Frame_Info[2] = HZ_Length + 3; 		//构造数据区长度的低字节
  Frame_Info[3] = 0x01 ; 			//构造命令字:合成播放命令
  Frame_Info[4] = 0x01 | Music << 4 ; //构造命令参数:背景音乐设定
 
  /*******************校验码计算***************************************/
  for(i = 0; i < 5; i++)   				//依次发送构造好的5个帧头字节
  {
    ecc = ecc ^ (Frame_Info[i]);		//对发送的字节进行异或校验
  }
 
  for(i = 0; i < HZ_Length; i++)   		//依次发送待合成的文本数据
  {
    ecc = ecc ^ (HZdata[i]); 				//对发送的字节进行异或校验
  }
  /*******************发送帧信息***************************************/
  memcpy(&Frame_Info[5], HZdata, HZ_Length);
  Frame_Info[5 + HZ_Length] = ecc;
  HAL_UART_Transmit(&huart2,Frame_Info,5 + HZ_Length + 1,10000);
}
 
 
/***********************************************************
* 名    称: YS_SYN_Set(u8 *Info_data)
* 功    能: 主函数	程序入口
* 入口参数: *Info_data:固定的配置信息变量
* 出口参数:
* 说    明:本函数用于配置,停止合成、暂停合成等设置 ,默认波特率9600bps。
* 调用方法:通过调用已经定义的相关数组进行配置。
**********************************************************/
void YS_SYN_Set(uint8_t *Info_data)
{
  uint8_t Com_Len;
  Com_Len = strlen((char*)Info_data);
  HAL_UART_Transmit(&huart2,Info_data,Com_Len,10000);
}
 

The voice broadcast of SYN6288 can be realized through  the SYN_FrameInfo function. SYN6288 has a high degree of integration, and can automatically analyze the data such as characters and Chinese characters sent, and further perform voice broadcast through the speaker (the development difficulty is extremely low!)

5.2 main code

In  the man function , SYN_FrameInf (uint8_t Music, uint8_t *HZdata) is used for voice broadcast, where Music is to select background music, 0: no background music, 1~15: select background music. HZdata is the data to be sent, and its format is [vx][mx][tx]"xxxxxxx"  .

[vx]: Foreground text playback volume , x volume value, value: 0~16 (where 0 is mute)

[mx]: background music volume, x is the volume value, value: 0~16 (where 0 is mute)

[tx]: Word speed, x is the word speed value, value: 0~5 (5 is the highest speed)

main.c:

#include "main.h"
#include "usart.h"
#include "gpio.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "syn6288.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/**************оƬÉèÖÃÃüÁî*********************/
uint8_t SYN_StopCom[] = {0xFD, 0X00, 0X02, 0X02, 0XFD}; //停止合成
uint8_t SYN_SuspendCom[] = {0XFD, 0X00, 0X02, 0X03, 0XFC}; //暂停合成
uint8_t SYN_RecoverCom[] = {0XFD, 0X00, 0X02, 0X04, 0XFB}; //恢复合成
uint8_t SYN_ChackCom[] = {0XFD, 0X00, 0X02, 0X21, 0XDE}; //状态查询
uint8_t SYN_PowerDownCom[] = {0XFD, 0X00, 0X02, 0X88, 0X77}; //进入POWER DOWN状态命令
/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART2_UART_Init();
  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
	  SYN_FrameInfo(2, "[v7][m1][t5]混分巨兽龙某某666");
	  HAL_Delay(1000);
  }
  /* USER CODE END 3 */
}

6. Code open source

Code address: SYN6288 voice broadcast module driver code resources based on STM32-CSDN library

If you don't have enough points, click Bo to follow , leave an email in the comment area , and the author will provide the source code and follow-up questions for free . Please pay attention to a wave! ! !

Guess you like

Origin blog.csdn.net/black_sneak/article/details/130951047