语音驱动程序  drv_voice.c

语音服务程序  srv_voice.c

1、先运行初始化函数,主要是设置初始音量,并建立一个软件定时器来,以10ms的周期来调用语音播放函数。

 1 void srvVoiceInit()
2 {
3 T_SOFT_TIMER_HANDLE hSoftTimer;
4 UINT16 usVoiceVolumeTunerAdjust;
5
6 g_hVoiceDevHandle = osalDevOpen(GEN20_PROTO_VOICE_DEV_NAME);
7 if (g_hVoiceDevHandle == INVALID_HANDLE)
8 {
9 LOG_ERROR_LOG(("srvVoiceInit failed at voice driver open.\r\n"));
10 }
11 else
12 {
13 /* Initialize voice play info structure, must before soft timer started. */
14 /* TODO: read default voice from EEPROM */
15 srvVoiSetDefaultVoiceType(VDVT_TYPE_A);
16 //g_tVoicePlayInfo.eSwitchStatus = VPSS_VOICE_IDLE;
17 gVoiPlayState = VPSS_VOICE_IDLE;
18 gVoiInnerEvent = E_NULL;
19 usVoiceVolumeTunerAdjust = 160;
20 //gVoiceToSet = 54;
21 srvSetVoiceVolume(63);
22 osalDevIoctl(g_hVoiceDevHandle, VOICE_CTRL_RST_PLAYBACK_CLR , NULL);
23 osalDevIoctl(g_hVoiceDevHandle, VOICE_CTRL_SET_VOICE_VOLUME, &usVoiceVolumeTunerAdjust);
24
25 /* Create the soft timer for push button service, the handle is not needed. */
26 if (OSAL_IS_RESULT_OK(osalTimCreateSoftTimer(&hSoftTimer, 10, STT_REPEAT, &srvVoicePlayTimerRoutine, NULL)))
27 {
28 if (OSAL_IS_RESULT_OK(osalTimStartSoftTimer(hSoftTimer)))
29 {
30 g_hVoiceMode = 0;
31 }
32 else
33 {
34 LOG_ERROR_LOG(("srvVoiceInit failed at SoftTimer start.\r\n"));
35 }
36 }
37 else
38 {
39 LOG_ERROR_LOG(("srvVoiceInit failed at SoftTimer create.\r\n"));
40 }
41 }
42 }

2 语音播放函数,先根据状态来设置语音模式,再根据模式来播放语音

 1 static void srvVoicePlayTimerRoutine(void *pvParam)
2 {
3 /* Wait event and return immediately. */
4 if(0 != g_hVoiceMode)
5 {
6 /* Some thing happened, adjust current voice play accordingly. */
7 srvVoiUpdateVoicePlayInfo(g_hVoiceMode);
8
9 /* Control voice play according to the information. */
10 srvVoiPlayVoice();
11 g_hVoiceMode = 0;
12 }
13 else
14 {
15 srvVoiPlayVoice();
16 }
17
18 }

3 更新语音播放信息,根据语音模式来更新

根据接收的语音事件来播放对应的语音片段,

语音包括以下

SRV_VOICE_PLAY_SYSTEM_START;系统启动声音

SRV_VOICE_PLAY_OPERATION_DENIED;操作禁止声音

SRV_VOICE_PLAY_TEST;测试声音

SRV_VOICE_PLAY_MIN_OUTPUT;小档位声音

SRV_VOICE_PLAY_MAX_OUTPUT;大档位声音

SRV_VOICE_PLAY_OVER_CURRENT;过流警报声

SRV_VOICE_PLAY_RECOVERABLE_FAULT;可恢复性错误声音

SRV_VOICE_PLAY_NON_RECOVERABLE_FAULT;不可恢复性错误

SRV_VOICE_PLAY_FAULT_REPLAY;错误重放

SRV_VOICE_PLAY_SHOW_DEFAULT_VOICE;默认语音

  1 static void srvVoiUpdateVoicePlayInfo(UINT uVoiceEvent)
2 {
3 if ((uVoiceEvent & SRV_VOICE_PLAY_SYSTEM_START) == SRV_VOICE_PLAY_SYSTEM_START)
4 {
5 /* Play welcome voice 1 time in fixed volume 60. */
6 gVoiInnerEvent = E_PLAY_VOICE;
7 g_tVoicePlayInfo.voiMode = VOI_MODE_REPEAT;
8 g_tVoicePlayInfo.wCurrVoiceSection = VOICE_SECTION_FLASH_START;
9 g_tVoicePlayInfo.usVoicePlayTimeIn10mS = VOICE_PLAY_DURATION_TIME_INFINITE;
10 g_tVoicePlayInfo.usVoicePlayRepeat = 1;
11 g_tVoicePlayInfo.usVoiceVolume = srvGetVoiceVolume();
12 //g_tVoicePlayInfo.usVoiceStopTimeoutIn10mS = 3;
13 g_tVoicePlayInfo.usVoiceStopIntervalTimeIn10mS = 10;
14 //g_tVoicePlayInfo.eSwitchStatus = VPSS_VOICE_START_PLAY;
15 }
16
17 if ((uVoiceEvent & SRV_VOICE_PLAY_OPERATION_DENIED) == SRV_VOICE_PLAY_OPERATION_DENIED)
18 {
19 /* Play welcome voice 1 time in fixed volume 60. */
20 gVoiInnerEvent = E_PLAY_VOICE;
21 g_tVoicePlayInfo.voiMode = VOI_MODE_REPEAT;
22 g_tVoicePlayInfo.wCurrVoiceSection = VOICE_SECTION_OPERATION_DENIED;
23 g_tVoicePlayInfo.usVoicePlayTimeIn10mS = VOICE_PLAY_DURATION_TIME_INFINITE;
24 g_tVoicePlayInfo.usVoicePlayRepeat = 1;
25 g_tVoicePlayInfo.usVoiceVolume = 60;
26 //g_tVoicePlayInfo.usVoiceStopTimeoutIn10mS = 3;
27 g_tVoicePlayInfo.usVoiceStopIntervalTimeIn10mS = 10;
28 //g_tVoicePlayInfo.eSwitchStatus = VPSS_VOICE_START_PLAY;
29 }
30 if ((uVoiceEvent & SRV_VOICE_PLAY_TEST) == SRV_VOICE_PLAY_TEST)
31 {
32 /* TODO: */
33 gVoiInnerEvent = E_PLAY_VOICE;
34 g_tVoicePlayInfo.voiMode = VOI_MODE_TIME_LIMITED;
35 g_tVoicePlayInfo.wCurrVoiceSection = VOICE_SECTION_TEST_IN_PROGRESS;
36 g_tVoicePlayInfo.usVoicePlayTimeIn10mS = VOICE_PLAY_DURATION_TIME_INFINITE;
37 g_tVoicePlayInfo.usVoicePlayRepeat = VOICE_PLAY_REPEAT_INFINITE;
38 g_tVoicePlayInfo.usVoiceVolume = srvGetVoiceVolume();
39 //g_tVoicePlayInfo.usVoiceStopTimeoutIn10mS = 3;
40 g_tVoicePlayInfo.usVoiceStopIntervalTimeIn10mS = 10;
41 //g_tVoicePlayInfo.eSwitchStatus = VPSS_VOICE_START_PLAY;
42 }
43 if ((uVoiceEvent & SRV_VOICE_PLAY_MIN_OUTPUT) == SRV_VOICE_PLAY_MIN_OUTPUT)
44 {
45 gVoiInnerEvent = E_PLAY_VOICE;
46 g_tVoicePlayInfo.voiMode = VOI_MODE_REPEAT;
47 g_tVoicePlayInfo.wCurrVoiceSection = g_tVoicePlayInfo.wVoiceDefaultMinOutput;
48 g_tVoicePlayInfo.usVoicePlayTimeIn10mS = VOICE_PLAY_DURATION_TIME_INFINITE;
49 g_tVoicePlayInfo.usVoicePlayRepeat = VOICE_PLAY_REPEAT_INFINITE;
50 g_tVoicePlayInfo.usVoiceVolume = srvGetVoiceVolume();// VOICE_PLAY_CURRENT_VOICE_VOLUME;
51 //g_tVoicePlayInfo.usVoiceStopTimeoutIn10mS = 3;
52 g_tVoicePlayInfo.usVoiceStopIntervalTimeIn10mS = 30; // last 26
53 //g_tVoicePlayInfo.eSwitchStatus = VPSS_VOICE_START_PLAY;
54 }
55 if ((uVoiceEvent & SRV_VOICE_PLAY_MAX_OUTPUT) == SRV_VOICE_PLAY_MAX_OUTPUT)
56 {
57 gVoiInnerEvent = E_PLAY_VOICE;
58 g_tVoicePlayInfo.voiMode = VOI_MODE_REPEAT;
59 g_tVoicePlayInfo.wCurrVoiceSection = g_tVoicePlayInfo.wVoiceDefaultMaxOutput;
60 g_tVoicePlayInfo.usVoicePlayTimeIn10mS = VOICE_PLAY_DURATION_TIME_INFINITE;
61 g_tVoicePlayInfo.usVoicePlayRepeat = VOICE_PLAY_REPEAT_INFINITE;
62 g_tVoicePlayInfo.usVoiceVolume = srvGetVoiceVolume(); //VOICE_PLAY_CURRENT_VOICE_VOLUME;
63 //g_tVoicePlayInfo.usVoiceStopTimeoutIn10mS = 3;
64 g_tVoicePlayInfo.usVoiceStopIntervalTimeIn10mS = 15; //last 10
65 //g_tVoicePlayInfo.eSwitchStatus = VPSS_VOICE_START_PLAY;
66 }
67 if ((uVoiceEvent & SRV_VOICE_PLAY_OVER_CURRENT) == SRV_VOICE_PLAY_OVER_CURRENT)
68 {
69 /* TODO: */
70 /* Play fatal error voice 1 time in fixed volume 60. */
71 gVoiInnerEvent = E_PLAY_VOICE;
72 g_tVoicePlayInfo.voiMode = VOI_MODE_REPEAT;
73 g_tVoicePlayInfo.wCurrVoiceSection = VOICE_SECTION_FATAL_ERROR;
74 g_tVoicePlayInfo.usVoicePlayTimeIn10mS = VOICE_PLAY_DURATION_TIME_INFINITE;
75 g_tVoicePlayInfo.usVoicePlayRepeat = 1;
76 g_tVoicePlayInfo.usVoiceVolume = 60;
77 //g_tVoicePlayInfo.usVoiceStopTimeoutIn10mS = 3;
78 g_tVoicePlayInfo.usVoiceStopIntervalTimeIn10mS = 10;
79 //g_tVoicePlayInfo.eSwitchStatus = VPSS_VOICE_START_PLAY;
80 }
81 if ((uVoiceEvent & SRV_VOICE_PLAY_RECOVERABLE_FAULT) == SRV_VOICE_PLAY_RECOVERABLE_FAULT)
82 {
83 /* Play fatal error voice 1 time in fixed volume 60. */
84 gVoiInnerEvent = E_PLAY_VOICE;
85 g_tVoicePlayInfo.voiMode = VOI_MODE_REPEAT;
86 g_tVoicePlayInfo.wCurrVoiceSection = VOICE_SECTION_FATAL_ERROR;
87 g_tVoicePlayInfo.usVoicePlayTimeIn10mS = VOICE_PLAY_DURATION_TIME_INFINITE;
88 g_tVoicePlayInfo.usVoicePlayRepeat = 1;//VOICE_PLAY_REPEAT_INFINITE;
89 g_tVoicePlayInfo.usVoiceVolume = 60;
90 //g_tVoicePlayInfo.usVoiceStopTimeoutIn10mS = 3;
91 g_tVoicePlayInfo.usVoiceStopIntervalTimeIn10mS = 10;
92 //g_tVoicePlayInfo.eSwitchStatus = VPSS_VOICE_START_PLAY;
93 }
94 if ((uVoiceEvent & SRV_VOICE_PLAY_NON_RECOVERABLE_FAULT) == SRV_VOICE_PLAY_NON_RECOVERABLE_FAULT)
95 {
96 /* Play fatal error voice 3 timeS in fixed volume 60. */
97 gVoiInnerEvent = E_PLAY_VOICE;
98 g_tVoicePlayInfo.voiMode = VOI_MODE_REPEAT;
99 g_tVoicePlayInfo.wCurrVoiceSection = VOICE_SECTION_FATAL_ERROR;
100 g_tVoicePlayInfo.usVoicePlayTimeIn10mS = VOICE_PLAY_DURATION_TIME_INFINITE;
101 g_tVoicePlayInfo.usVoicePlayRepeat = 1;//VOICE_PLAY_REPEAT_INFINITE;
102 g_tVoicePlayInfo.usVoiceVolume = 60;
103 //g_tVoicePlayInfo.usVoiceStopTimeoutIn10mS = 3;
104 g_tVoicePlayInfo.usVoiceStopIntervalTimeIn10mS = 10;
105 //g_tVoicePlayInfo.eSwitchStatus = VPSS_VOICE_START_PLAY;
106 }
107 if ((uVoiceEvent & SRV_VOICE_PLAY_FAULT_REPLAY) == SRV_VOICE_PLAY_FAULT_REPLAY)
108 {
109 /* Play fatal error voice 1 time in fixed volume 60. */
110 gVoiInnerEvent = E_PLAY_VOICE;
111 g_tVoicePlayInfo.voiMode = VOI_MODE_REPEAT;
112 g_tVoicePlayInfo.wCurrVoiceSection = VOICE_SECTION_FATAL_ERROR;
113 g_tVoicePlayInfo.usVoicePlayTimeIn10mS = VOICE_PLAY_DURATION_TIME_INFINITE;
114 g_tVoicePlayInfo.usVoicePlayRepeat = 1;
115 g_tVoicePlayInfo.usVoiceVolume = 60;
116 //g_tVoicePlayInfo.usVoiceStopTimeoutIn10mS = 3;
117 g_tVoicePlayInfo.usVoiceStopIntervalTimeIn10mS = 10;
118 //g_tVoicePlayInfo.eSwitchStatus = VPSS_VOICE_START_PLAY;
119 }
120 if ((uVoiceEvent & SRV_VOICE_PLAY_SHOW_DEFAULT_VOICE) == SRV_VOICE_PLAY_SHOW_DEFAULT_VOICE)
121 {
122 gVoiInnerEvent = E_PLAY_VOICE;
123 g_tVoicePlayInfo.voiMode = VOI_MODE_REPEAT;
124 g_tVoicePlayInfo.wCurrVoiceSection = VOICE_PLAY_DEFAULT_VOICE_SECTION;
125 g_tVoicePlayInfo.usVoicePlayTimeIn10mS = 100;
126 g_tVoicePlayInfo.usVoicePlayRepeat = VOICE_PLAY_REPEAT_INFINITE;
127 g_tVoicePlayInfo.usVoiceVolume = srvGetVoiceVolume();
128 g_tVoicePlayInfo.usVoiceStopIntervalTimeIn10mS = 10;
129 //g_tVoicePlayInfo.usVoiceStopTimeoutIn10mS = 3;
130 //g_tVoicePlayInfo.eSwitchStatus = VPSS_VOICE_START_PLAY;
131 }
132 if ((uVoiceEvent & SRV_VOICE_PLAY_STOP) == SRV_VOICE_PLAY_STOP)
133 {
134 /* Stop current play, don't change wCurrVoiceSection, left it done in srvVoiPlayVoice(). */
135 gVoiInnerEvent = E_STOP_VOICE ;
136 //g_tVoicePlayInfo.usVoiceStopTimeoutIn10mS = 3;
137 g_tVoicePlayInfo.usVoicePlayRepeat = 1;
138 g_tVoicePlayInfo.usVoiceVolume = 60; //
139 //g_tVoicePlayInfo.eSwitchStatus = VPSS_VOICE_EXPLICIT_STOP_PLAY;
140 }
141 }

4 语音信息结构体

 1 typedef struct{
2 VOI_MODE_TYPE voiMode;
3 UINT16 wCurrVoiceSection; /* 当前语音段. */
4 UINT16 usVoicePlayTimeIn10mS; /* 语音总时长. */
5 UINT16 usVoiceStopIntervalTimeIn10mS; /* 重复播放的间隔时间 */
6 UINT16 usVoiceStopIntervalRemainTimeIn10mS; /* 间隔时间的剩余量. */
7 //UINT16 usVoiceStopTimeoutIn10mS; /* Timeout when checking whether voice stopped. */
8 UINT16 usVoicePlayRepeat; /* 语音重复次数 */
9 UINT16 usVoiceVolume; /* 音量 */
10 UINT16 wVoiceDefaultMaxOutput;
11 UINT16 wVoiceDefaultMinOutput;
12 } T_VOICE_PLAY_INFO;

5 播放语音

static void srvVoiPlayVoice(void)
{
UINT16 wVoiceSection; //语音段
//UINT16 usVoiceVolumeTunerAdjust;
UINT16 usVoiceVolumeToSet; //设置的音量
UINT16 wVoiceStatus; //语音状态
T_OSAL_RESULT eRslt = OSAL_OK;
static UINT16 wLastVoiceStatus = 0; //上一次语音的状态
static UINT32 ticForwait;//等待的时钟数
static E_VOICE_PLAY_SWITCH_STATUS afterResetState = VPSS_VOICE_IDLE; if(gVoiPlayState != VPSS_VOICE_IDLE)
{ //语音状态非IDLE状态
if(gVoiInnerEvent == E_PLAY_VOICE)
{
gVoiPlayState = VPSS_VOICE_RESET;
afterResetState = VPSS_VOICE_LOAD_VOICE;
}else if(gVoiInnerEvent == E_STOP_VOICE){
gVoiPlayState = VPSS_VOICE_RESET;
afterResetState = VPSS_VOICE_IDLE;
}
} switch (gVoiPlayState)
{
case VPSS_VOICE_IDLE:
if(gVoiInnerEvent == E_PLAY_VOICE)
{
gVoiPlayState = VPSS_VOICE_LOAD_VOICE;
}
break; case VPSS_VOICE_LOAD_VOICE:
usVoiceVolumeToSet = g_tVoicePlayInfo.usVoiceVolume;
eRslt = osalDevIoctl(g_hVoiceDevHandle, VOICE_CTRL_SET_VOICE_VOLUME, &usVoiceVolumeToSet);//设置音量 if (OSAL_IS_RESULT_OK(eRslt))
{ //等音量设置完
wVoiceSection = g_tVoicePlayInfo.wCurrVoiceSection;
eRslt = osalDevWrite(g_hVoiceDevHandle, &wVoiceSection, 1); //加载待播放的语音 if (OSAL_IS_RESULT_OK(eRslt))
{ //等待语音加载完成
if(g_tVoicePlayInfo.voiMode == VOI_MODE_REPEAT)
{ //播放模式为重复播放模式
ticForwait = osalTimGetOSTime();
gVoiPlayState = VPSS_VOICE_TRIGGER_WAIT;
}
else if(g_tVoicePlayInfo.voiMode == VOI_MODE_TIME_LIMITED)
{ //限时播放模式
gVoiPlayState = VPSS_VOICE_PLAY_TIME_LIMITED;
}
}else{
LOG_ERROR_LOG(("Voice driver write failed. Error: %08x.\r\n", eRslt));
}
}else{
LOG_ERROR_LOG(("Voice driver ioctl failed. Error: %08x.\r\n", eRslt));
}
break; case VPSS_VOICE_TRIGGER_WAIT:
//wait 100ms
if((osalTimGetOSTime() -ticForwait) > 1000)
{
wVoiceSection = VOICE_SECTION_NULL;
eRslt = osalDevWrite(g_hVoiceDevHandle, &wVoiceSection, 1);
gVoiPlayState = VPSS_VOICE_PLAY_REPEAT;
}
break; case VPSS_VOICE_PLAY_REPEAT:
eRslt = osalDevIoctl(g_hVoiceDevHandle, VOICE_CTRL_READ_STATUS, &wVoiceStatus);
if (OSAL_IS_RESULT_OK(eRslt))
{
/* Check if current playing is finished */
if((wVoiceStatus == 0x0000) )//&(wLastVoiceStatus == 0x0001)
{
wLastVoiceStatus = 0;
g_tVoicePlayInfo.usVoiceStopIntervalRemainTimeIn10mS = g_tVoicePlayInfo.usVoiceStopIntervalTimeIn10mS;
gVoiPlayState = VPSS_VOICE_RELOAD_VOICE;
}else{
wLastVoiceStatus = wVoiceStatus;
}
}else{
LOG_ERROR_LOG(("Voice driver ioctl failed. Error: %08x.\r\n", eRslt));
}
break; case VPSS_VOICE_RELOAD_VOICE: if(g_tVoicePlayInfo.usVoiceStopIntervalRemainTimeIn10mS != 0)
{
g_tVoicePlayInfo.usVoiceStopIntervalRemainTimeIn10mS --;
}else{
if(g_tVoicePlayInfo.usVoicePlayRepeat != 0){
if(g_tVoicePlayInfo.usVoicePlayRepeat != VOICE_PLAY_REPEAT_INFINITE)
{
g_tVoicePlayInfo.usVoicePlayRepeat--;
}
if(g_tVoicePlayInfo.usVoicePlayRepeat != 0)
{
wVoiceSection = g_tVoicePlayInfo.wCurrVoiceSection;
eRslt = osalDevWrite(g_hVoiceDevHandle, &wVoiceSection, 1);
ticForwait = osalTimGetOSTime();
gVoiPlayState = VPSS_VOICE_TRIGGER_WAIT;
}
else{
gVoiPlayState = VPSS_VOICE_IDLE;
}
}else{
gVoiPlayState = VPSS_VOICE_IDLE;
}
}
break; case VPSS_VOICE_RESET:
wVoiceSection = VOICE_SECTION_NULL;
eRslt = osalDevWrite(g_hVoiceDevHandle, &wVoiceSection, 1);
eRslt = osalDevIoctl(g_hVoiceDevHandle, VOICE_CTRL_RST_PLAYBACK_SET, NULL);
ticForwait = osalTimGetOSTime();
gVoiPlayState = VPSS_VOICE_RESET_WAIT;
break; case VPSS_VOICE_RESET_WAIT:
if((osalTimGetOSTime() - ticForwait) > 500)
{
eRslt = osalDevIoctl(g_hVoiceDevHandle, VOICE_CTRL_RST_PLAYBACK_CLR , NULL);
gVoiPlayState = afterResetState;
}
break; case VPSS_VOICE_PLAY_TIME_LIMITED:
if(g_tVoicePlayInfo.usVoicePlayTimeIn10mS != VOICE_PLAY_DURATION_TIME_INFINITE )
{
if(g_tVoicePlayInfo.usVoicePlayTimeIn10mS != 0)
{
g_tVoicePlayInfo.usVoicePlayTimeIn10mS--;
}
else
{
gVoiPlayState = VPSS_VOICE_RESET;
afterResetState = VPSS_VOICE_IDLE;
}
}
break;
}
gVoiInnerEvent = E_NULL; }

最新文章

  1. Sublime插件支持Sass编译和Babel解析ES6 & .sublime-build文件初探
  2. Oracle查看用户操作sql语句以及数据库日志
  3. 数据结构-链表逆置(c++模板类实现)
  4. Table of Contents - jBPM
  5. C#控件列表
  6. 你好,C++(37)上车的人请买票!6.3.3 用虚函数实现多态
  7. [Java] Tcp/udp 简单通信
  8. [置顶] 北漂的大三IT男(暂完)
  9. hdu 1232 畅通project
  10. hdu3899(树形dp)
  11. 一个简单的string类,读书看报系列(一)
  12. js观察者模式与Model
  13. RDMA调研报告&一点随笔
  14. oracle 之创建定时器
  15. JMeter安装+配置+运行
  16. SQL Server 的动态语句(SQLServer 的String.format用法)(SQLServer的调用SQL占位符的使用)
  17. IOS 程序员开发最常用宏定义
  18. swift中,Optional、?与!之间的关系
  19. webpack开发和生产两个环境的配置详解
  20. 洛谷P2300 合并神犇

热门文章

  1. 比较一下 Java 和 JavaSciprt?
  2. C++11最常用的新特性如下
  3. spring-boot-learning-使用jsp
  4. CKEditor禁用浏览服务器的功能
  5. Java 中,Maven 和 ANT 有什么区别?
  6. Java 中,编写多线程程序的时候你会遵循哪些最佳实践?
  7. springboot gateway 动态路由-01
  8. Leetcode1——两数之和 详细解析
  9. DASCTF Oct吉林工师web
  10. 从零开始画自己的DAG作业依赖图(四)--节点连线优化版