|
1
|
-#include <fstream>
|
|
|
|
2
|
-#include <assert.h>
|
|
|
|
3
|
-#include <cstring>
|
|
|
|
4
|
-#include <atomic>
|
|
|
|
5
|
-#include <unistd.h>
|
|
|
|
6
|
-#include <string>
|
1
|
+// #include <fstream>
|
|
|
|
2
|
+// #include <assert.h>
|
|
|
|
3
|
+// #include <cstring>
|
|
|
|
4
|
+// #include <atomic>
|
|
|
|
5
|
+// #include <unistd.h>
|
|
|
|
6
|
+// #include <string>
|
|
7
|
|
7
|
|
|
8
|
-#include "JZsdkLib.h"
|
|
|
|
9
|
-#include "version_choose.h"
|
8
|
+// #include "JZsdkLib.h"
|
|
|
|
9
|
+// #include "version_choose.h"
|
|
|
|
10
|
+// #include "JZsdk_base/JZring/JZring.h"
|
|
10
|
|
11
|
|
|
11
|
-#ifdef IFLAY_TTS_2_CONFIG_STATUS_ON
|
12
|
+// #ifdef IFLAY_TTS_2_CONFIG_STATUS_ON
|
|
12
|
|
13
|
|
|
13
|
-#include "aikit_biz_api.h"
|
|
|
|
14
|
-#include "aikit_constant.h"
|
|
|
|
15
|
-#include "aikit_biz_config.h"
|
|
|
|
16
|
-#include "iflytek_tts.h"
|
|
|
|
17
|
-#include "AudioDeal/AudioDeal.h"
|
|
|
|
18
|
-#include "../../Megaphone.h"
|
|
|
|
19
|
-#include "iflytek_tts.h"
|
14
|
+// #include "aikit_biz_api.h"
|
|
|
|
15
|
+// #include "aikit_constant.h"
|
|
|
|
16
|
+// #include "aikit_biz_config.h"
|
|
|
|
17
|
+// #include "iflytek_tts.h"
|
|
|
|
18
|
+// #include "AudioDeal/AudioDeal.h"
|
|
|
|
19
|
+// #include "../../Megaphone.h"
|
|
|
|
20
|
+// #include "iflytek_tts.h"
|
|
20
|
|
21
|
|
|
21
|
|
22
|
|
|
22
|
-using namespace std;
|
|
|
|
23
|
-using namespace AIKIT;
|
23
|
+// using namespace std;
|
|
|
|
24
|
+// using namespace AIKIT;
|
|
24
|
|
25
|
|
|
25
|
-static std::atomic_bool ttsFinished(false);
|
|
|
|
26
|
-static const char *ABILITY = "e2e44feff";
|
|
|
|
27
|
-static AIKIT_HANDLE *g_AikitHandle = nullptr; //合成句柄
|
26
|
+// static std::atomic_bool ttsFinished(false);
|
|
|
|
27
|
+// static const char *ABILITY = "e2e44feff";
|
|
|
|
28
|
+// static AIKIT_HANDLE *g_AikitHandle = nullptr; //合成句柄
|
|
28
|
|
29
|
|
|
29
|
-static int IflytekLib_2_StopTts();
|
30
|
+// static int IflytekLib_2_StopTts();
|
|
30
|
|
31
|
|
|
31
|
-static FILE *iflytts_fp = NULL;
|
|
|
|
32
|
-#define IFLYTTS_FP_NAME "/root/tmp_tts_file.pcm"
|
32
|
+// static FILE *iflytts_fp = NULL;
|
|
|
|
33
|
+// #define IFLYTTS_FP_NAME "/root/tmp_tts_file.pcm"
|
|
33
|
|
34
|
|
|
34
|
|
35
|
|
|
35
|
-void OnOutput(AIKIT_HANDLE* handle, const AIKIT_OutputData* output)
|
|
|
|
36
|
-{
|
|
|
|
37
|
- //检测数据生成标志位是否有关闭,如果有关闭,则主动关闭合成,并退出该事件
|
|
|
|
38
|
- if (Megaphone_MegDataGenFlag(JZ_FLAGCODE_GET, 0) == JZ_FLAGCODE_OFF)
|
|
|
|
39
|
- {
|
|
|
|
40
|
- IflytekLib_2_StopTts();
|
|
|
|
41
|
- return;
|
|
|
|
42
|
- }
|
36
|
+// void OnOutput(AIKIT_HANDLE* handle, const AIKIT_OutputData* output)
|
|
|
|
37
|
+// {
|
|
|
|
38
|
+// //检测数据生成标志位是否有关闭,如果有关闭,则主动关闭合成,并退出该事件
|
|
|
|
39
|
+// if (Megaphone_MegDataGenFlag(JZ_FLAGCODE_GET, 0) == JZ_FLAGCODE_OFF)
|
|
|
|
40
|
+// {
|
|
|
|
41
|
+// IflytekLib_2_StopTts();
|
|
|
|
42
|
+// return;
|
|
|
|
43
|
+// }
|
|
43
|
|
44
|
|
|
44
|
- //如果存在数据,则播放
|
|
|
|
45
|
- if (output->node->value)
|
|
|
|
46
|
- {
|
|
|
|
47
|
- //生产的文本数据 output->node->value
|
|
|
|
48
|
- //生产的数据长度 output->node->len
|
|
|
|
49
|
- //char类型
|
45
|
+// //如果存在数据,则播放
|
|
|
|
46
|
+// if (output->node->value)
|
|
|
|
47
|
+// {
|
|
|
|
48
|
+// //生产的文本数据 output->node->value
|
|
|
|
49
|
+// //生产的数据长度 output->node->len
|
|
|
|
50
|
+// //char类型
|
|
50
|
|
51
|
|
|
51
|
- //JZSDK_LOG_DEBUG("生产了数据%d", output->node->len);
|
|
|
|
52
|
- printf("生产了数据%d\n", output->node->len);
|
52
|
+// //JZSDK_LOG_DEBUG("生产了数据%d", output->node->len);
|
|
|
|
53
|
+// printf("生产了数据%d\n", output->node->len);
|
|
53
|
|
54
|
|
|
54
|
- //将该数据发送到alsa播放器
|
|
|
|
55
|
- //AudioDeal_PcmDataInput_TextSteam(16000, (unsigned char *)output->node->value, output->node->len);
|
55
|
+// //将该数据发送到alsa播放器
|
|
|
|
56
|
+// //AudioDeal_PcmDataInput_TextSteam(16000, (unsigned char *)output->node->value, output->node->len);
|
|
56
|
|
57
|
|
|
57
|
- if (iflytts_fp != NULL)
|
|
|
|
58
|
- {
|
|
|
|
59
|
- fwrite(output->node->value, sizeof(char), output->node->len, iflytts_fp);
|
|
|
|
60
|
- fflush(iflytts_fp);
|
|
|
|
61
|
- }
|
58
|
+// if (iflytts_fp != NULL)
|
|
|
|
59
|
+// {
|
|
|
|
60
|
+// fwrite(output->node->value, sizeof(char), output->node->len, iflytts_fp);
|
|
|
|
61
|
+// fflush(iflytts_fp);
|
|
|
|
62
|
+// }
|
|
62
|
|
63
|
|
|
63
|
- }
|
|
|
|
64
|
-
|
|
|
|
65
|
-
|
|
|
|
66
|
-}
|
|
|
|
67
|
-
|
|
|
|
68
|
-void OnEvent(AIKIT_HANDLE* handle, AIKIT_EVENT eventType, const AIKIT_OutputEvent* eventValue) {
|
|
|
|
69
|
- if (eventType == AIKIT_Event_End) {
|
|
|
|
70
|
- ttsFinished = true;
|
|
|
|
71
|
-
|
|
|
|
72
|
- JZSDK_LOG_INFO("合成完成");
|
|
|
|
73
|
- }
|
|
|
|
74
|
-}
|
64
|
+// }
|
|
|
|
65
|
+
|
|
|
|
66
|
+
|
|
|
|
67
|
+// }
|
|
|
|
68
|
+
|
|
|
|
69
|
+// void OnEvent(AIKIT_HANDLE* handle, AIKIT_EVENT eventType, const AIKIT_OutputEvent* eventValue) {
|
|
|
|
70
|
+// if (eventType == AIKIT_Event_End) {
|
|
|
|
71
|
+// ttsFinished = true;
|
|
|
|
72
|
+
|
|
|
|
73
|
+// JZSDK_LOG_INFO("合成完成");
|
|
|
|
74
|
+// }
|
|
|
|
75
|
+// }
|
|
|
|
76
|
+
|
|
|
|
77
|
+// void OnError(AIKIT_HANDLE* handle, int32_t err, const char* desc) {
|
|
|
|
78
|
+// printf("OnError:%d\n", err);
|
|
75
|
|
79
|
|
|
76
|
-void OnError(AIKIT_HANDLE* handle, int32_t err, const char* desc) {
|
|
|
|
77
|
- printf("OnError:%d\n", err);
|
80
|
+// //报错
|
|
|
|
81
|
+// }
|
|
|
|
82
|
+
|
|
|
|
83
|
+// int IflytekLib_2_TextToTts(int language,
|
|
|
|
84
|
+// const char *TtsRole,
|
|
|
|
85
|
+// const char *text, int speed, int volume)
|
|
|
|
86
|
+// {
|
|
|
|
87
|
+
|
|
|
|
88
|
+// if (iflytts_fp != NULL)
|
|
|
|
89
|
+// {
|
|
|
|
90
|
+// JZSDK_LOG_ERROR("file %s is not closed\n", IFLYTTS_FP_NAME);
|
|
|
|
91
|
+// return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
|
|
|
|
92
|
+// }
|
|
|
|
93
|
+
|
|
|
|
94
|
+
|
|
|
|
95
|
+// AIKIT_ParamBuilder* paramBuilder = nullptr;
|
|
|
|
96
|
+// AIKIT_DataBuilder* dataBuilder = nullptr;
|
|
|
|
97
|
+// AiText* aiText_raw = nullptr;
|
|
78
|
|
98
|
|
|
79
|
- //报错
|
|
|
|
80
|
-}
|
|
|
|
81
|
-
|
|
|
|
82
|
-int IflytekLib_2_TextToTts(int language,
|
|
|
|
83
|
- const char *TtsRole,
|
|
|
|
84
|
- const char *text, int speed, int volume)
|
|
|
|
85
|
-{
|
|
|
|
86
|
-
|
|
|
|
87
|
- if (iflytts_fp != NULL)
|
|
|
|
88
|
- {
|
|
|
|
89
|
- JZSDK_LOG_ERROR("file %s is not closed\n", IFLYTTS_FP_NAME);
|
|
|
|
90
|
- return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
|
|
|
|
91
|
- }
|
|
|
|
92
|
-
|
|
|
|
93
|
-
|
|
|
|
94
|
- AIKIT_ParamBuilder* paramBuilder = nullptr;
|
|
|
|
95
|
- AIKIT_DataBuilder* dataBuilder = nullptr;
|
|
|
|
96
|
- AiText* aiText_raw = nullptr;
|
|
|
|
97
|
|
99
|
|
|
|
|
100
|
+// // 重置完成标志
|
|
|
|
101
|
+// ttsFinished = false;
|
|
98
|
|
102
|
|
|
99
|
- // 重置完成标志
|
|
|
|
100
|
- ttsFinished = false;
|
103
|
+// paramBuilder = AIKIT_ParamBuilder::create();
|
|
|
|
104
|
+// paramBuilder->clear();
|
|
|
|
105
|
+// // 设置发音人
|
|
|
|
106
|
+// paramBuilder->param("vcn", TtsRole, strlen(TtsRole));
|
|
|
|
107
|
+// paramBuilder->param("vcnModel", TtsRole, strlen(TtsRole));
|
|
|
|
108
|
+// // 设置语种
|
|
|
|
109
|
+// paramBuilder->param("language", language);
|
|
|
|
110
|
+// // 设置文本编码
|
|
|
|
111
|
+// paramBuilder->param("textEncoding", "UTF-8", strlen("UTF-8"));
|
|
101
|
|
112
|
|
|
102
|
- paramBuilder = AIKIT_ParamBuilder::create();
|
|
|
|
103
|
- paramBuilder->clear();
|
|
|
|
104
|
- // 设置发音人
|
|
|
|
105
|
- paramBuilder->param("vcn", TtsRole, strlen(TtsRole));
|
|
|
|
106
|
- paramBuilder->param("vcnModel", TtsRole, strlen(TtsRole));
|
|
|
|
107
|
- // 设置语种
|
|
|
|
108
|
- paramBuilder->param("language", language);
|
|
|
|
109
|
- // 设置文本编码
|
|
|
|
110
|
- paramBuilder->param("textEncoding", "UTF-8", strlen("UTF-8"));
|
113
|
+// //语速
|
|
|
|
114
|
+// paramBuilder->param("speed",speed); //可选参数,默认为0
|
|
111
|
|
115
|
|
|
112
|
- //语速
|
|
|
|
113
|
- paramBuilder->param("speed",speed); //可选参数,默认为0
|
116
|
+// //音调
|
|
|
|
117
|
+// //paramBuilder->param("pitch",100); //可选参数,默认为0
|
|
114
|
|
118
|
|
|
115
|
- //音调
|
|
|
|
116
|
- //paramBuilder->param("pitch",100); //可选参数,默认为0
|
119
|
+// //声音
|
|
|
|
120
|
+// //paramBuilder->param("volume",100);//可选参数,默认为0
|
|
117
|
|
121
|
|
|
118
|
- //声音
|
|
|
|
119
|
- //paramBuilder->param("volume",100);//可选参数,默认为0
|
122
|
+// //打开临存文件
|
|
|
|
123
|
+// iflytts_fp = fopen(IFLYTTS_FP_NAME, "w+b");
|
|
|
|
124
|
+// if (iflytts_fp == NULL)
|
|
|
|
125
|
+// {
|
|
|
|
126
|
+// JZSDK_LOG_ERROR("open file %s failed\n", IFLYTTS_FP_NAME);
|
|
|
|
127
|
+// return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
|
|
|
|
128
|
+// }
|
|
120
|
|
129
|
|
|
121
|
- //打开临存文件
|
|
|
|
122
|
- iflytts_fp = fopen(IFLYTTS_FP_NAME, "w+b");
|
|
|
|
123
|
- if (iflytts_fp == NULL)
|
|
|
|
124
|
- {
|
|
|
|
125
|
- JZSDK_LOG_ERROR("open file %s failed\n", IFLYTTS_FP_NAME);
|
|
|
|
126
|
- return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
|
|
|
|
127
|
- }
|
130
|
+// //JZSDK_LOG_DEBUG("TTS Role:%s Len:%d, Text:%s Len:%d, language:%d", TtsRole, strlen(TtsRole), text, strlen(text), language);
|
|
128
|
|
131
|
|
|
129
|
- //JZSDK_LOG_DEBUG("TTS Role:%s Len:%d, Text:%s Len:%d, language:%d", TtsRole, strlen(TtsRole), text, strlen(text), language);
|
132
|
+// int ret = AIKIT_Start(ABILITY, AIKIT_Builder::build(paramBuilder), nullptr, &g_AikitHandle);
|
|
|
|
133
|
+// if(ret != 0) {
|
|
|
|
134
|
+// printf("AIKIT_Start failed: %d\n", ret);
|
|
|
|
135
|
+// goto exit;
|
|
|
|
136
|
+// }
|
|
130
|
|
137
|
|
|
131
|
- int ret = AIKIT_Start(ABILITY, AIKIT_Builder::build(paramBuilder), nullptr, &g_AikitHandle);
|
|
|
|
132
|
- if(ret != 0) {
|
|
|
|
133
|
- printf("AIKIT_Start failed: %d\n", ret);
|
|
|
|
134
|
- goto exit;
|
|
|
|
135
|
- }
|
138
|
+// dataBuilder = AIKIT_DataBuilder::create();
|
|
|
|
139
|
+// dataBuilder->clear();
|
|
|
|
140
|
+// //aiText_raw = AiText::get("text")->data(text.c_str(), text.length())->once()->valid();
|
|
|
|
141
|
+// aiText_raw = AiText::get("text")->data(text, strlen(text) )->once()->valid();
|
|
|
|
142
|
+// dataBuilder->payload(aiText_raw);
|
|
136
|
|
143
|
|
|
137
|
- dataBuilder = AIKIT_DataBuilder::create();
|
|
|
|
138
|
- dataBuilder->clear();
|
|
|
|
139
|
- //aiText_raw = AiText::get("text")->data(text.c_str(), text.length())->once()->valid();
|
|
|
|
140
|
- aiText_raw = AiText::get("text")->data(text, strlen(text) )->once()->valid();
|
|
|
|
141
|
- dataBuilder->payload(aiText_raw);
|
144
|
+// ret = AIKIT_Write(g_AikitHandle, AIKIT_Builder::build(dataBuilder));
|
|
|
|
145
|
+// if(ret != 0) {
|
|
|
|
146
|
+// printf("AIKIT_Write failed: %d\n", ret);
|
|
|
|
147
|
+// goto exit;
|
|
|
|
148
|
+// }
|
|
142
|
|
149
|
|
|
143
|
- ret = AIKIT_Write(g_AikitHandle, AIKIT_Builder::build(dataBuilder));
|
|
|
|
144
|
- if(ret != 0) {
|
|
|
|
145
|
- printf("AIKIT_Write failed: %d\n", ret);
|
|
|
|
146
|
- goto exit;
|
|
|
|
147
|
- }
|
150
|
+// // 等待合成完成
|
|
|
|
151
|
+// while(!ttsFinished) {
|
|
|
|
152
|
+// usleep(1000);
|
|
|
|
153
|
+// }
|
|
148
|
|
154
|
|
|
149
|
- // 等待合成完成
|
|
|
|
150
|
- while(!ttsFinished) {
|
|
|
|
151
|
- usleep(1000);
|
|
|
|
152
|
- }
|
155
|
+// JZSDK_LOG_DEBUG("合成完成,开始播放");
|
|
153
|
|
156
|
|
|
154
|
- JZSDK_LOG_DEBUG("合成完成,开始播放");
|
157
|
+// //将fp指针移到文件开头
|
|
|
|
158
|
+// fseek(iflytts_fp, 0, SEEK_SET);
|
|
155
|
|
159
|
|
|
156
|
- //将fp指针移到文件开头
|
|
|
|
157
|
- fseek(iflytts_fp, 0, SEEK_SET);
|
160
|
+// //将数据导入播放器
|
|
|
|
161
|
+// unsigned char buffer[1024];
|
|
|
|
162
|
+// int len;
|
|
|
|
163
|
+// while (Megaphone_MegDataGenFlag(JZ_FLAGCODE_GET, 0) != JZ_FLAGCODE_OFF)
|
|
|
|
164
|
+// {
|
|
|
|
165
|
+// len = fread(buffer, sizeof(char), 1024, iflytts_fp);
|
|
|
|
166
|
+// if (len <= 0)
|
|
|
|
167
|
+// {
|
|
|
|
168
|
+// JZSDK_LOG_DEBUG("已读取完毕\n");
|
|
|
|
169
|
+// break;
|
|
|
|
170
|
+// }
|
|
158
|
|
171
|
|
|
159
|
- //将数据导入播放器
|
|
|
|
160
|
- unsigned char buffer[1024];
|
|
|
|
161
|
- int len;
|
|
|
|
162
|
- while (Megaphone_MegDataGenFlag(JZ_FLAGCODE_GET, 0) != JZ_FLAGCODE_OFF)
|
|
|
|
163
|
- {
|
|
|
|
164
|
- len = fread(buffer, sizeof(char), 1024, iflytts_fp);
|
|
|
|
165
|
- if (len <= 0)
|
|
|
|
166
|
- {
|
|
|
|
167
|
- JZSDK_LOG_DEBUG("已读取完毕\n");
|
|
|
|
168
|
- break;
|
|
|
|
169
|
- }
|
172
|
+// AudioDeal_PcmDataInput_TextSteam(16000, buffer, len);
|
|
|
|
173
|
+// }
|
|
170
|
|
174
|
|
|
171
|
- AudioDeal_PcmDataInput_TextSteam(16000, buffer, len);
|
|
|
|
172
|
- }
|
175
|
+// JZSDK_LOG_INFO("播放完成");
|
|
173
|
|
176
|
|
|
174
|
- JZSDK_LOG_INFO("播放完成");
|
177
|
+// ret = AIKIT_End(g_AikitHandle);
|
|
175
|
|
178
|
|
|
176
|
- ret = AIKIT_End(g_AikitHandle);
|
179
|
+// exit:
|
|
|
|
180
|
+// if(paramBuilder != nullptr) {
|
|
|
|
181
|
+// delete paramBuilder;
|
|
|
|
182
|
+// }
|
|
|
|
183
|
+// if(dataBuilder != nullptr) {
|
|
|
|
184
|
+// delete dataBuilder;
|
|
|
|
185
|
+// }
|
|
177
|
|
186
|
|
|
178
|
-exit:
|
|
|
|
179
|
- if(paramBuilder != nullptr) {
|
|
|
|
180
|
- delete paramBuilder;
|
|
|
|
181
|
- }
|
|
|
|
182
|
- if(dataBuilder != nullptr) {
|
|
|
|
183
|
- delete dataBuilder;
|
|
|
|
184
|
- }
|
187
|
+// if (iflytts_fp != NULL)
|
|
|
|
188
|
+// {
|
|
|
|
189
|
+// fclose(iflytts_fp);
|
|
|
|
190
|
+// iflytts_fp = NULL;
|
|
|
|
191
|
+// }
|
|
185
|
|
192
|
|
|
186
|
- if (iflytts_fp != NULL)
|
|
|
|
187
|
- {
|
|
|
|
188
|
- fclose(iflytts_fp);
|
|
|
|
189
|
- iflytts_fp = NULL;
|
|
|
|
190
|
- }
|
193
|
+// return 0;
|
|
|
|
194
|
+// }
|
|
191
|
|
195
|
|
|
192
|
- return 0;
|
|
|
|
193
|
-}
|
|
|
|
194
|
|
196
|
|
|
195
|
|
197
|
|
|
196
|
|
198
|
|
|
@@ -202,47 +204,116 @@ exit: |
|
@@ -202,47 +204,116 @@ exit: |
|
202
|
|
204
|
|
|
203
|
|
205
|
|
|
204
|
|
206
|
|
|
205
|
-int IflytekLib_2_Init()
|
|
|
|
206
|
-{
|
|
|
|
207
|
- AIKIT_Configurator::builder()
|
|
|
|
208
|
- .app()
|
|
|
|
209
|
- .appID("03857dfd")
|
|
|
|
210
|
- .apiSecret("OTA2OTEzMTVlOGYwMjllMmJkYzEwZGY5")
|
|
|
|
211
|
- .apiKey("2b2c60f8a80b8cdfe45ae1058a25149a")
|
|
|
|
212
|
- .workDir("/root/Iflytek_2")
|
|
|
|
213
|
- .auth()
|
|
|
|
214
|
- .authType(0)
|
|
|
|
215
|
- .log()
|
|
|
|
216
|
- .logLevel(LOG_LVL_OFF) //关闭日志打印
|
|
|
|
217
|
- .logMode(LOG_STDOUT); //日志输出为控制台
|
207
|
+// int IflytekLib_2_UnInit()
|
|
|
|
208
|
+// {
|
|
|
|
209
|
+// AIKIT_UnInit();
|
|
|
|
210
|
+// return 0;
|
|
|
|
211
|
+// }
|
|
218
|
|
212
|
|
|
219
|
- int ret = AIKIT_Init();
|
|
|
|
220
|
- if(ret != 0) {
|
|
|
|
221
|
- printf("AIKIT_Init failed: %d\n", ret);
|
|
|
|
222
|
- return -1;
|
|
|
|
223
|
- }
|
213
|
+// static int IflytekLib_2_StopTts()
|
|
|
|
214
|
+// {
|
|
|
|
215
|
+// AIKIT_OutputEvent eventData = {};
|
|
|
|
216
|
+// if (g_AikitHandle != nullptr)
|
|
|
|
217
|
+// {
|
|
|
|
218
|
+// OnEvent(g_AikitHandle,AIKIT_Event_End,&eventData);
|
|
|
|
219
|
+// }
|
|
224
|
|
220
|
|
|
225
|
- AIKIT_Callbacks cbs = {OnOutput, OnEvent, OnError};
|
|
|
|
226
|
- AIKIT_RegisterAbilityCallback(ABILITY, cbs);
|
221
|
+// return 0;
|
|
|
|
222
|
+// }
|
|
227
|
|
223
|
|
|
228
|
- return 0;
|
|
|
|
229
|
-}
|
|
|
|
230
|
|
224
|
|
|
231
|
-int IflytekLib_2_UnInit()
|
|
|
|
232
|
-{
|
|
|
|
233
|
- AIKIT_UnInit();
|
|
|
|
234
|
- return 0;
|
|
|
|
235
|
-}
|
|
|
|
236
|
|
225
|
|
|
237
|
-static int IflytekLib_2_StopTts()
|
|
|
|
238
|
-{
|
|
|
|
239
|
- AIKIT_OutputEvent eventData = {};
|
|
|
|
240
|
- if (g_AikitHandle != nullptr)
|
|
|
|
241
|
- {
|
|
|
|
242
|
- OnEvent(g_AikitHandle,AIKIT_Event_End,&eventData);
|
|
|
|
243
|
- }
|
|
|
|
244
|
|
226
|
|
|
245
|
- return 0;
|
|
|
|
246
|
-}
|
|
|
|
247
|
|
227
|
|
|
248
|
-#endif |
|
|
|
|
|
228
|
+
|
|
|
|
229
|
+
|
|
|
|
230
|
+
|
|
|
|
231
|
+
|
|
|
|
232
|
+
|
|
|
|
233
|
+// #define IFLYTEK_RING_BUF_SIZE (1024 * 100) // 100KB缓冲区
|
|
|
|
234
|
+// static T_JZringHandle g_ringHandle = nullptr;
|
|
|
|
235
|
+// static char *g_ringBuf = nullptr;
|
|
|
|
236
|
+// static int g_AudioPlayFinshFlag = JZ_FLAGCODE_OFF;
|
|
|
|
237
|
+// static int g_playThreadRunning = JZ_FLAGCODE_OFF;
|
|
|
|
238
|
+
|
|
|
|
239
|
+// static void PlaybackThreadFunc()
|
|
|
|
240
|
+// {
|
|
|
|
241
|
+// T_JZsdkOsalHandler *osHandler = JZsdk_Platform_GetOsalHandler;
|
|
|
|
242
|
+// U8_t buffer[2048]; // 每次读取2KB
|
|
|
|
243
|
+// U32_t readSize = 0;
|
|
|
|
244
|
+// T_JZsdkReturnCode ret;
|
|
|
|
245
|
+// U32_t dataCount = 0;
|
|
|
|
246
|
+
|
|
|
|
247
|
+// g_playThreadRunning = JZ_FLAGCODE_ON;
|
|
|
|
248
|
+
|
|
|
|
249
|
+// while (g_playThreadRunning == JZ_FLAGCODE_ON)
|
|
|
|
250
|
+// {
|
|
|
|
251
|
+// //监测缓冲区是否有数据
|
|
|
|
252
|
+// dataCount = 0;
|
|
|
|
253
|
+// ret = JZring_GetDataCount(g_ringHandle, &dataCount);
|
|
|
|
254
|
+
|
|
|
|
255
|
+// if (dataCount == 0)
|
|
|
|
256
|
+// {
|
|
|
|
257
|
+// //等候线程唤醒
|
|
|
|
258
|
+
|
|
|
|
259
|
+// continue;
|
|
|
|
260
|
+// }
|
|
|
|
261
|
+
|
|
|
|
262
|
+// //读取数据
|
|
|
|
263
|
+// ret = JZring_Read(g_ringHandle, buffer, sizeof(buffer), &readSize);
|
|
|
|
264
|
+// if (ret != JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
|
|
|
|
265
|
+// {
|
|
|
|
266
|
+// JZSDK_LOG_ERROR("读取环形缓冲区失败");
|
|
|
|
267
|
+// break;
|
|
|
|
268
|
+// }
|
|
|
|
269
|
+
|
|
|
|
270
|
+// //写入音频播放器
|
|
|
|
271
|
+// AudioDeal_PcmDataInput_TextSteam(16000, buffer, readSize);
|
|
|
|
272
|
+
|
|
|
|
273
|
+// g_AudioPlayFinshFlag = JZ_FLAGCODE_ON;
|
|
|
|
274
|
+
|
|
|
|
275
|
+// //检查
|
|
|
|
276
|
+// }
|
|
|
|
277
|
+// }
|
|
|
|
278
|
+
|
|
|
|
279
|
+// T_JZsdkReturnCode IflytekLib_2_Init()
|
|
|
|
280
|
+// {
|
|
|
|
281
|
+// //初始化环形缓冲区
|
|
|
|
282
|
+// g_ringBuf = new char[IFLYTEK_RING_BUF_SIZE];
|
|
|
|
283
|
+// if (JZring_Init(&g_ringHandle, reinterpret_cast<U8_t*>(g_ringBuf), IFLYTEK_RING_BUF_SIZE)
|
|
|
|
284
|
+// != JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
|
|
|
285
|
+// JZSDK_LOG_ERROR("环形缓冲区初始化失败");
|
|
|
|
286
|
+// return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
|
|
|
|
287
|
+// }
|
|
|
|
288
|
+
|
|
|
|
289
|
+// T_JZsdkOsalHandler *osHandler = JZsdk_Platform_GetOsalHandler;
|
|
|
|
290
|
+// T_JZTaskHandle taskhandle;
|
|
|
|
291
|
+// osHandler->TaskCreate("IfytekLibPlay", PlaybackThreadFunc, 1024, NULL, &taskhandle);
|
|
|
|
292
|
+
|
|
|
|
293
|
+// AIKIT_Configurator::builder()
|
|
|
|
294
|
+// .app()
|
|
|
|
295
|
+// .appID("03857dfd")
|
|
|
|
296
|
+// .apiSecret("OTA2OTEzMTVlOGYwMjllMmJkYzEwZGY5")
|
|
|
|
297
|
+// .apiKey("2b2c60f8a80b8cdfe45ae1058a25149a")
|
|
|
|
298
|
+// .workDir("/root/Iflytek_2")
|
|
|
|
299
|
+// .auth()
|
|
|
|
300
|
+// .authType(0)
|
|
|
|
301
|
+// .log()
|
|
|
|
302
|
+// .logLevel(LOG_LVL_OFF) //关闭日志打印
|
|
|
|
303
|
+// .logMode(LOG_STDOUT); //日志输出为控制台
|
|
|
|
304
|
+
|
|
|
|
305
|
+// int ret = AIKIT_Init();
|
|
|
|
306
|
+// if(ret != 0) {
|
|
|
|
307
|
+// printf("AIKIT_Init failed: %d\n", ret);
|
|
|
|
308
|
+// return -1;
|
|
|
|
309
|
+// }
|
|
|
|
310
|
+
|
|
|
|
311
|
+// AIKIT_Callbacks cbs = {OnOutput, OnEvent, OnError};
|
|
|
|
312
|
+// AIKIT_RegisterAbilityCallback(ABILITY, cbs);
|
|
|
|
313
|
+
|
|
|
|
314
|
+// return 0;
|
|
|
|
315
|
+// }
|
|
|
|
316
|
+
|
|
|
|
317
|
+
|
|
|
|
318
|
+
|
|
|
|
319
|
+// #endif |