Skip to content

Commit 5399074

Browse files
authored
Merge pull request #31 from aliyun/sdk_3.2
Update VERSION 3.2.1b
2 parents 1e2e874 + 3b953d7 commit 5399074

6 files changed

+1227
-80
lines changed

demo/Linux/CMakeLists.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ add_executable(srDemo profile_scan.cpp speechRecognizerDemo.cpp)
3939
target_link_libraries(srDemo
4040
alibabacloud-idst-speech ${NLS_DEMO_EXT_FLAG})
4141

42-
add_executable(srMT profile_scan.cpp speechRecognizerMonkeyTest.cpp)
42+
add_executable(srMT speechRecognizerMonkeyTest.cpp)
4343
target_link_libraries(srMT
4444
alibabacloud-idst-speech ${NLS_DEMO_EXT_FLAG})
4545

@@ -48,7 +48,7 @@ add_executable(stDemo profile_scan.cpp speechTranscriberDemo.cpp)
4848
target_link_libraries(stDemo
4949
alibabacloud-idst-speech ${NLS_DEMO_EXT_FLAG})
5050

51-
add_executable(stMT profile_scan.cpp speechTranscriberMonkeyTest.cpp)
51+
add_executable(stMT speechTranscriberMonkeyTest.cpp)
5252
target_link_libraries(stMT
5353
alibabacloud-idst-speech ${NLS_DEMO_EXT_FLAG})
5454

@@ -66,6 +66,10 @@ add_executable(fsDemo profile_scan.cpp flowingSynthesizerDemo.cpp)
6666
target_link_libraries(fsDemo
6767
alibabacloud-idst-speech ${NLS_DEMO_EXT_FLAG})
6868

69+
add_executable(fsMT flowingSynthesizerMonkeyTest.cpp)
70+
target_link_libraries(fsMT
71+
alibabacloud-idst-speech ${NLS_DEMO_EXT_FLAG})
72+
6973
# 对话助手
7074
add_executable(daDemo dialogAssistantDemo.cpp)
7175
target_link_libraries(daDemo

demo/Linux/flowingSynthesizerDemo.cpp

+52-26
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <sys/time.h>
2727
#include <sys/types.h>
2828
#include <unistd.h>
29+
2930
#include <cstdlib>
3031
#include <ctime>
3132
#include <fstream>
@@ -236,6 +237,22 @@ std::string timestamp_str() {
236237
return tmp;
237238
}
238239

240+
bool isNotEmptyAndNotSpace(const char* str) {
241+
if (str == NULL) {
242+
return false;
243+
}
244+
size_t length = strlen(str);
245+
if (length == 0) {
246+
return false;
247+
}
248+
for (size_t i = 0; i < length; ++i) {
249+
if (!std::isspace(static_cast<unsigned char>(str[i]))) {
250+
return true;
251+
}
252+
}
253+
return false;
254+
}
255+
239256
static void vectorSetParams(unsigned long pid, bool add,
240257
struct ParamStatistics params) {
241258
pthread_mutex_lock(&params_mtx);
@@ -1095,6 +1112,8 @@ void* pthreadFunc(void* arg) {
10951112
// start()调用超时,cancel()取消当次请求。
10961113
request->cancel();
10971114
run_cancel++;
1115+
AlibabaNls::NlsClient::getInstance()
1116+
->releaseFlowingSynthesizerRequest(request);
10981117
break;
10991118
}
11001119
pthread_mutex_unlock(&(cbParam.mtxWord));
@@ -1134,30 +1153,33 @@ void* pthreadFunc(void* arg) {
11341153
std::cout << "total text: " << text_str << std::endl;
11351154
for (std::vector<std::string>::const_iterator it = sentences.begin();
11361155
it != sentences.end(); ++it) {
1137-
std::cout << "sendText: " << *it << std::endl;
1138-
ret = request->sendText(it->c_str());
1139-
if (ret < 0) {
1140-
break;
1141-
}
1142-
if (sendFlushFlag) {
1143-
if (enableLongSilence) {
1144-
request->sendFlush("{\"enable_long_silence\":true}");
1145-
} else {
1146-
request->sendFlush();
1156+
if (isNotEmptyAndNotSpace(it->c_str())) {
1157+
std::cout << "sendText: " << *it << std::endl;
1158+
ret = request->sendText(it->c_str());
1159+
if (ret < 0) {
1160+
break;
1161+
}
1162+
if (sendFlushFlag) {
1163+
if (enableLongSilence) {
1164+
request->sendFlush("{\"enable_long_silence\":true}");
1165+
} else {
1166+
request->sendFlush();
1167+
}
11471168
}
1169+
usleep(500 * 1000);
11481170
}
1149-
usleep(500 * 1000);
11501171

11511172
if (!global_run) break;
11521173
} // for
11531174
if (ret < 0) {
1154-
std::cout << "sendText failed. pid:" << pthread_self() << std::endl;
1175+
std::cout << "sendText failed. pid:" << pthread_self()
1176+
<< ". ret: " << ret << std::endl;
11551177
const char* request_info = request->dumpAllInfo();
11561178
if (request_info) {
11571179
std::cout << " all info: " << request_info << std::endl;
11581180
}
11591181
AlibabaNls::NlsClient::getInstance()->releaseFlowingSynthesizerRequest(
1160-
request); // start()失败,释放request对象
1182+
request);
11611183
break;
11621184
}
11631185
}
@@ -1200,8 +1222,10 @@ void* pthreadFunc(void* arg) {
12001222
pthread_mutex_lock(&(cbParam.mtxWord));
12011223
if (ETIMEDOUT == pthread_cond_timedwait(&(cbParam.cvWord),
12021224
&(cbParam.mtxWord), &outtime)) {
1203-
std::cout << "stop timeout" << std::endl;
1225+
std::cout << "stop timeout, release this request" << std::endl;
12041226
pthread_mutex_unlock(&(cbParam.mtxWord));
1227+
AlibabaNls::NlsClient::getInstance()
1228+
->releaseFlowingSynthesizerRequest(request);
12051229
break;
12061230
}
12071231
pthread_mutex_unlock(&(cbParam.mtxWord));
@@ -1283,7 +1307,7 @@ void* pthreadLongConnectionFunc(void* arg) {
12831307
* 1. 创建流式文本语音合成FlowingSynthesizerRequest对象.
12841308
*
12851309
* 流式文本语音合成文档详见:
1286-
* https://help.aliyun.com/zh/isi/developer-reference/streaming-text-to-speech-synthesis/?spm=a2c4g.11186623.0.0.638b1f016dQylG
1310+
* https://help.aliyun.com/zh/isi/developer-reference/streaming-text-to-speech-synthesis
12871311
*/
12881312
AlibabaNls::FlowingSynthesizerRequest* request =
12891313
AlibabaNls::NlsClient::getInstance()->createFlowingSynthesizerRequest(
@@ -1475,19 +1499,21 @@ void* pthreadLongConnectionFunc(void* arg) {
14751499
std::cout << "total text: " << text_str << std::endl;
14761500
for (std::vector<std::string>::const_iterator it = sentences.begin();
14771501
it != sentences.end(); ++it) {
1478-
std::cout << "sendText: " << *it << std::endl;
1479-
ret = request->sendText(it->c_str());
1480-
if (ret < 0) {
1481-
break;
1482-
}
1483-
if (sendFlushFlag) {
1484-
if (enableLongSilence) {
1485-
request->sendFlush("{\"enable_long_silence\":true}");
1486-
} else {
1487-
request->sendFlush();
1502+
if (isNotEmptyAndNotSpace(it->c_str())) {
1503+
std::cout << "sendText: " << *it << std::endl;
1504+
ret = request->sendText(it->c_str());
1505+
if (ret < 0) {
1506+
break;
1507+
}
1508+
if (sendFlushFlag) {
1509+
if (enableLongSilence) {
1510+
request->sendFlush("{\"enable_long_silence\":true}");
1511+
} else {
1512+
request->sendFlush();
1513+
}
14881514
}
1515+
usleep(500 * 1000);
14891516
}
1490-
usleep(500 * 1000);
14911517

14921518
if (!global_run) break;
14931519
} // for

0 commit comments

Comments
 (0)