当前位置:   article > 正文

STM32传感器外设集--语音模块(SYN6288)_syn6288语音模块

syn6288语音模块

目录

前言

 代码编写

SYN6288.h

SYN6288.c

stm32f10x_it.h

 main.c

参考 


前言

如何使用该模块呢,首先,SYN6288是使用串口通讯的,很多模块其实都是使用串口通讯,有助于指令的输入,那么使用串口通讯就简单了,首先配置串口等

 代码编写

SYN6288.h

这里的话我使用的是串口4,当然C8T6的话是只要三个串口的,如何需要使用,可以自行修改串口配置

  1. #ifndef _SYN6288_H_
  2. #define _SYN6288_H_
  3. #include "stm32f10x.h"
  4. /**
  5. ******************************************************************************
  6. * @File SYN6288.h
  7. * @Author Velscode
  8. * @Email velscode@gmail.com
  9. * @Brief TTS 芯片 SYN6288驱动头文件(基于STM32F10x)
  10. * 使用了USART2(A2\A3)
  11. ******************************************************************************
  12. */
  13. /****************************** SYN6288 引脚配置参数定义***************************************/
  14. #define SYN6288_GPIO_APBxClock_FUN RCC_APB2PeriphClockCmd
  15. #define SYN6288_GPIO_CLK RCC_APB2Periph_GPIOC
  16. #define SYN6288_GPIO_PORT GPIOC
  17. #define SYN6288_GPIO_PIN GPIO_Pin_6
  18. #define SYN6288_Read_GPIO_IN() GPIO_ReadInputDataBit ( SYN6288_GPIO_PORT, SYN6288_GPIO_PIN )
  19. // 串口4-UART4
  20. #define DEBUG_USARTx UART4
  21. #define DEBUG_USART_CLK RCC_APB1Periph_UART4
  22. #define DEBUG_USART_APBxClkCmd RCC_APB1PeriphClockCmd
  23. #define DEBUG_USART_BAUDRATE 9600
  24. // USART GPIO 引脚宏定义
  25. #define DEBUG_USART_GPIO_CLK (RCC_APB2Periph_GPIOC)
  26. #define DEBUG_USART_GPIO_APBxClkCmd RCC_APB2PeriphClockCmd
  27. #define DEBUG_USART_TX_GPIO_PORT GPIOC
  28. #define DEBUG_USART_TX_GPIO_PIN GPIO_Pin_10
  29. #define DEBUG_USART_RX_GPIO_PORT GPIOC
  30. #define DEBUG_USART_RX_GPIO_PIN GPIO_Pin_11
  31. #define DEBUG_USART_IRQ UART4_IRQn
  32. #define DEBUG_USART_IRQHandler UART4_IRQHandler
  33. void SYN6288_GPIO_Config ( void );
  34. void Usart_SendHalfWord( USART_TypeDef * pUSARTx, uint16_t ch);
  35. void SYN6288_Speech( USART_TypeDef * pUSARTx,char * str );
  36. void SYN688_USART_Config(void);
  37. void Usart_SendByte( USART_TypeDef * pUSARTx, uint8_t ch);
  38. void SYN_FrameInfo(char *HZdata);
  39. void Usart_SendString( USART_TypeDef * pUSARTx, char *str);
  40. /* 音量控制 */
  41. void Volinme(uint8_t Y_L);
  42. /* 语调控制 */
  43. void Intonation(uint8_t Y_L);
  44. /* 语速控制 */
  45. void Speed_pacing(uint8_t Y_L);
  46. /* 人控制 */
  47. void speed_man(uint8_t Y_L);
  48. #endif /*_SYN6288_H_*/
  49. /* End of File ------------------------------------------------------------- */

SYN6288.c

这里的话就是配置参数,还有给SYN6288发指令等

  1. /**
  2. ******************************************************************************
  3. * @File SYN6288.c
  4. * @Author Velscode
  5. * @Email velscode@gmail.com
  6. * @Brief TTS 芯片 SYN6288驱动源代码文件(基于STM32F10x)
  7. * 使用了USART2(A2\A3
  8. ******************************************************************************
  9. */
  10. /* Internal Function Declaration ------------------------------------------- */
  11. void usart2_Init(unsigned int bound);
  12. /* Header Files ------------------------------------------------------------ */
  13. #include "SYN6288.h"
  14. #include "string.h"
  15. #include "bsp_SysTick.h"
  16. #include <string.h>
  17. /**
  18. * @brief 配置嵌套向量中断控制器NVIC
  19. * @param 无
  20. * @retval 无
  21. */
  22. static void NVIC_Configuration(void)
  23. {
  24. NVIC_InitTypeDef NVIC_InitStructure;
  25. /* 嵌套向量中断控制器组选择 */
  26. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  27. /* 配置USART为中断源 */
  28. NVIC_InitStructure.NVIC_IRQChannel = DEBUG_USART_IRQ;
  29. /* 抢断优先级*/
  30. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  31. /* 子优先级 */
  32. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  33. /* 使能中断 */
  34. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  35. /* 初始化配置NVIC */
  36. NVIC_Init(&NVIC_InitStructure);
  37. }
  38. //读忙
  39. void SYN6288_GPIO_Config ( void )
  40. {
  41. /*定义一个GPIO_InitTypeDef类型的结构体*/
  42. GPIO_InitTypeDef GPIO_InitStructure;
  43. /* 配置 LED1 引脚 */
  44. SYN6288_GPIO_APBxClock_FUN(SYN6288_GPIO_CLK, ENABLE);
  45. GPIO_InitStructure.GPIO_Pin = SYN6288_GPIO_PIN;
  46. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  47. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  48. GPIO_Init ( SYN6288_GPIO_PORT, & GPIO_InitStructure );
  49. }
  50. /**
  51. * @brief USART GPIO 配置,工作参数配置
  52. * @param 无
  53. * @retval 无
  54. */
  55. void SYN688_USART_Config(void)
  56. {
  57. GPIO_InitTypeDef GPIO_InitStructure;
  58. USART_InitTypeDef USART_InitStructure;
  59. // 打开串口GPIO的时钟
  60. DEBUG_USART_GPIO_APBxClkCmd(DEBUG_USART_GPIO_CLK, ENABLE);
  61. // 打开串口外设的时钟
  62. DEBUG_USART_APBxClkCmd(DEBUG_USART_CLK, ENABLE);
  63. // 将USART Tx的GPIO配置为推挽复用模式
  64. GPIO_InitStructure.GPIO_Pin = DEBUG_USART_TX_GPIO_PIN;
  65. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  66. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  67. GPIO_Init(DEBUG_USART_TX_GPIO_PORT, &GPIO_InitStructure);
  68. // 将USART Rx的GPIO配置为浮空输入模式
  69. GPIO_InitStructure.GPIO_Pin = DEBUG_USART_RX_GPIO_PIN;
  70. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  71. GPIO_Init(DEBUG_USART_RX_GPIO_PORT, &GPIO_InitStructure);
  72. // 配置串口的工作参数
  73. // 配置波特率
  74. USART_InitStructure.USART_BaudRate = DEBUG_USART_BAUDRATE;
  75. // 配置 针数据字长
  76. USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  77. // 配置停止位
  78. USART_InitStructure.USART_StopBits = USART_StopBits_1;
  79. // 配置校验位
  80. USART_InitStructure.USART_Parity = USART_Parity_No ;
  81. // 配置硬件流控制
  82. USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  83. // 配置工作模式,收发一起
  84. USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  85. // 完成串口的初始化配置
  86. USART_Init(DEBUG_USARTx, &USART_InitStructure);
  87. // 串口中断优先级配置
  88. NVIC_Configuration();
  89. // 使能串口接收中断
  90. USART_ITConfig(DEBUG_USARTx, USART_IT_RXNE, ENABLE);
  91. // 使能串口
  92. USART_Cmd(DEBUG_USARTx, ENABLE);
  93. // 清除发送完成标志
  94. //USART_ClearFlag(USART1, USART_FLAG_TC);
  95. }
  96. //其实是USART2_Send_Byte
  97. /***************** 发送一个字符 **********************/
  98. void Usart_SendByte( USART_TypeDef * pUSARTx, uint8_t ch)
  99. {
  100. /* 发送一个字节数据到USART */
  101. USART_SendData(pUSARTx,ch);
  102. /* 等待发送数据寄存器为空 */
  103. while (USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET);
  104. }
  105. /***************** 发送字符串 **********************/
  106. void Usart_SendString( USART_TypeDef * pUSARTx, char *str)
  107. {
  108. unsigned int k=0;
  109. do
  110. {
  111. Usart_SendByte( pUSARTx, *(str + k) );
  112. k++;
  113. } while(*(str + k)!='\0');
  114. /* 等待发送完成 */
  115. while(USART_GetFlagStatus(pUSARTx,USART_FLAG_TC)==RESET)
  116. {}
  117. }
  118. //语音合成
  119. void SYN6288_Speech( USART_TypeDef * pUSARTx,char * str )
  120. {
  121. if(SYN6288_Read_GPIO_IN()==Bit_RESET)/* x us后仍为高电平表示数据“1*/
  122. {
  123. char * p = str;
  124. int len = 0,check=0xFD,i;
  125. while( *p++ != 0 )
  126. {
  127. len++;
  128. }
  129. len+=3;
  130. Usart_SendByte(DEBUG_USARTx,0xFD);
  131. Usart_SendByte( DEBUG_USARTx,len / 256 );
  132. Usart_SendByte( DEBUG_USARTx,len % 256 );
  133. check = check ^ ( len / 256 ) ^ ( len % 256 );
  134. Usart_SendByte( DEBUG_USARTx,0x01 );
  135. Usart_SendByte( DEBUG_USARTx,0x01 );
  136. check = check ^ 0x01 ^ 0x01;
  137. for( i = 0; i < len-3; i++ )
  138. {
  139. Usart_SendByte(DEBUG_USARTx,*str);
  140. check ^= ( *str );
  141. str++;
  142. }
  143. Usart_SendByte(DEBUG_USARTx,check);
  144. Delay_ms(150*len);
  145. }
  146. }
  147. /* 音量控制 */
  148. void Volinme(uint8_t Y_L)
  149. {
  150. uint8_t num ;
  151. num = Y_L+48;
  152. Usart_SendByte(DEBUG_USARTx,0xFD);
  153. Usart_SendByte(DEBUG_USARTx,0x00);
  154. Usart_SendByte(DEBUG_USARTx,0x06);
  155. Usart_SendByte(DEBUG_USARTx,0x01);
  156. Usart_SendByte(DEBUG_USARTx,0x01);
  157. Usart_SendByte(DEBUG_USARTx,0x5B);
  158. Usart_SendByte(DEBUG_USARTx,0x76);
  159. //控制音量
  160. Usart_SendByte(DEBUG_USARTx,num);
  161. Usart_SendByte(DEBUG_USARTx,0x5D);
  162. // uint8_t num[9] ;
  163. //
  164. // num[0] = 0xFD;
  165. // num[1] = 0x00;
  166. // num[2] = 0x06;
  167. // num[3] = 0x01;
  168. // num[4] = 0x01;
  169. // num[5] = 0x5B;
  170. // num[6] = 0x76;
  171. // //控制音量
  172. // num[7] = Y_L+48;
  173. // num[8] = 0x5D;
  174. //
  175. // Usart_SendByte(DEBUG_USARTx,num[8]);
  176. }
  177. /* 语调控制 */
  178. void Intonation(uint8_t Y_L)
  179. {
  180. uint8_t num ;
  181. num = Y_L+48;
  182. Usart_SendByte(DEBUG_USARTx,0xFD);
  183. Usart_SendByte(DEBUG_USARTx,0x00);
  184. Usart_SendByte(DEBUG_USARTx,0x06);
  185. Usart_SendByte(DEBUG_USARTx,0x01);
  186. Usart_SendByte(DEBUG_USARTx,0x01);
  187. Usart_SendByte(DEBUG_USARTx,0x5B);
  188. Usart_SendByte(DEBUG_USARTx,0x74);
  189. //控制音量
  190. Usart_SendByte(DEBUG_USARTx,num);
  191. Usart_SendByte(DEBUG_USARTx,0x5D);
  192. }
  193. /* 语速控制 */
  194. void Speed_pacing(uint8_t Y_L)
  195. {
  196. uint8_t num ;
  197. num = Y_L+48;
  198. Usart_SendByte(DEBUG_USARTx,0xFD);
  199. Usart_SendByte(DEBUG_USARTx,0x00);
  200. Usart_SendByte(DEBUG_USARTx,0x06);
  201. Usart_SendByte(DEBUG_USARTx,0x01);
  202. Usart_SendByte(DEBUG_USARTx,0x01);
  203. Usart_SendByte(DEBUG_USARTx,0x5B);
  204. Usart_SendByte(DEBUG_USARTx,0x73);
  205. //控制音量
  206. Usart_SendByte(DEBUG_USARTx,num);
  207. Usart_SendByte(DEBUG_USARTx,0x5D);
  208. }
  209. /* 人控制 */
  210. void speed_man(uint8_t Y_L)
  211. {
  212. uint8_t num ;
  213. num = Y_L+48;
  214. Usart_SendByte(DEBUG_USARTx,0xFD);
  215. Usart_SendByte(DEBUG_USARTx,0x00);
  216. Usart_SendByte(DEBUG_USARTx,0x07);
  217. Usart_SendByte(DEBUG_USARTx,0x01);
  218. Usart_SendByte(DEBUG_USARTx,0x01);
  219. Usart_SendByte(DEBUG_USARTx,0x5B);
  220. Usart_SendByte(DEBUG_USARTx,0x6D);
  221. Usart_SendByte(DEBUG_USARTx,0x35);
  222. //控制音量
  223. Usart_SendByte(DEBUG_USARTx,num);
  224. Usart_SendByte(DEBUG_USARTx,0x5D);
  225. }
  226. /* End of File ------------------------------------------------------------- */

stm32f10x_it.h

 写完配置函数,当然不能忘记配置中断服务,把这段代码加入该文件的中,那么你的SYN8622还差一步就大功告成了

  1. #include "SYN6288.h"
  2. // 串口中断服务函数
  3. void DEBUG_USART_IRQHandler(void)
  4. {
  5. uint8_t ucCh;
  6. if ( USART_GetITStatus ( DEBUG_USARTx, USART_IT_RXNE ) != RESET )
  7. {
  8. ucCh = USART_ReceiveData( DEBUG_USARTx );
  9. if ( strUSART_Fram_Record .InfBit .FramLength < ( RX_BUF_MAX_LEN - 1 ) ) //预留1个字节写结束符
  10. strUSART_Fram_Record .Data_RX_BUF [ strUSART_Fram_Record .InfBit .FramLength ++ ] = ucCh;
  11. }
  12. if ( USART_GetITStatus( DEBUG_USARTx, USART_IT_IDLE ) == SET ) //数据帧接收完毕
  13. {
  14. strUSART_Fram_Record .InfBit .FramFinishFlag = 1;
  15. ucCh = USART_ReceiveData( DEBUG_USARTx ); //由软件序列清除中断标志位(先读USART_SR,然后读USART_DR)
  16. }
  17. }

 main.c

  1. #include "bsp_usart1.h"
  2. #include "stm32f10x.h"
  3. #include "bsp_SysTick.h"
  4. #include "SYN6288.h"
  5. void Rap_And_God(void);
  6. /**
  7. * @brief 主函数
  8. * @param 无
  9. * @retval 无
  10. */
  11. int main ( void )
  12. {
  13. /* 初始化 */
  14. USARTx_Config ();
  15. //USART_Config (); //初始化串口1
  16. SysTick_Init (); //配置 SysTick 为 1ms 中断一次 //初始化WiFi模块使用的接口和外设
  17. //初始化RGB彩灯
  18. //语音播报系统
  19. SYN6288_GPIO_Config();
  20. SYN688_USART_Config();
  21. printf ( "\r\n 语音控制识别系统(Android+WiFi) \r\n" );
  22. while(1){
  23. Rap_And_God();
  24. };
  25. }
  26. /**
  27. * @brief 封装语音函数
  28. * @param 无
  29. * @retval 无
  30. */
  31. void Rap_And_God(void)
  32. {
  33. SYN6288_Speech(DEBUG_USARTx,"粉红的长裙");
  34. SYN6288_Speech(DEBUG_USARTx,"蓬松的头发");
  35. SYN6288_Speech(DEBUG_USARTx,"牵着我的手看最新展出的油画");
  36. SYN6288_Speech(DEBUG_USARTx,"无人的街道");
  37. SYN6288_Speech(DEBUG_USARTx,"在空荡的家里");
  38. SYN6288_Speech(DEBUG_USARTx,"就只剩我一个人狂欢的趴体");
  39. SYN6288_Speech(DEBUG_USARTx,"就当是一场梦");
  40. SYN6288_Speech(DEBUG_USARTx,"醒了还是很感动");
  41. SYN6288_Speech(DEBUG_USARTx,"还是很想被你保护我心里的惨痛");
  42. SYN6288_Speech(DEBUG_USARTx,"喜欢我很辛苦");
  43. SYN6288_Speech(DEBUG_USARTx,"其实我都清楚");
  44. SYN6288_Speech(DEBUG_USARTx,"放心这世界很大我记得你的叮嘱");
  45. }
  46. /*********************************************END OF FILE**********************/

参考 

第二章 SYN6288语音合成模块的使用icon-default.png?t=N7T8https://blog.csdn.net/qq_44645742/article/details/124871041?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522170212810616800185858985%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=170212810616800185858985&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_click~default-1-124871041-null-null.142^v96^pc_search_result_base7&utm_term=syn6288%E6%A8%A1%E5%9D%97%E4%BD%BF%E7%94%A8&spm=1018.2226.3001.4187基于STM32 + SYN6288语音播报icon-default.png?t=N7T8https://blog.csdn.net/zhouml_msn/article/details/125204251?ops_request_misc=&request_id=&biz_id=102&utm_term=syn6288%E6%A8%A1%E5%9D%97%E4%BD%BF%E7%94%A8&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-2-125204251.nonecase&spm=1018.2226.3001.4187

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/396608
推荐阅读
相关标签
  

闽ICP备14008679号