Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions demo/Linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ add_executable(srDemo profile_scan.cpp speechRecognizerDemo.cpp)
target_link_libraries(srDemo
alibabacloud-idst-speech ${NLS_DEMO_EXT_FLAG})

add_executable(srMT profile_scan.cpp speechRecognizerMonkeyTest.cpp)
add_executable(srMT speechRecognizerMonkeyTest.cpp)
target_link_libraries(srMT
alibabacloud-idst-speech ${NLS_DEMO_EXT_FLAG})

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

add_executable(stMT profile_scan.cpp speechTranscriberMonkeyTest.cpp)
add_executable(stMT speechTranscriberMonkeyTest.cpp)
target_link_libraries(stMT
alibabacloud-idst-speech ${NLS_DEMO_EXT_FLAG})

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

add_executable(fsMT flowingSynthesizerMonkeyTest.cpp)
target_link_libraries(fsMT
alibabacloud-idst-speech ${NLS_DEMO_EXT_FLAG})

# 对话助手
add_executable(daDemo dialogAssistantDemo.cpp)
target_link_libraries(daDemo
Expand Down
78 changes: 52 additions & 26 deletions demo/Linux/flowingSynthesizerDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

#include <cstdlib>
#include <ctime>
#include <fstream>
Expand Down Expand Up @@ -236,6 +237,22 @@ std::string timestamp_str() {
return tmp;
}

bool isNotEmptyAndNotSpace(const char* str) {
if (str == NULL) {
return false;
}
size_t length = strlen(str);
if (length == 0) {
return false;
}
for (size_t i = 0; i < length; ++i) {
if (!std::isspace(static_cast<unsigned char>(str[i]))) {
return true;
}
}
return false;
}

static void vectorSetParams(unsigned long pid, bool add,
struct ParamStatistics params) {
pthread_mutex_lock(&params_mtx);
Expand Down Expand Up @@ -1095,6 +1112,8 @@ void* pthreadFunc(void* arg) {
// start()调用超时,cancel()取消当次请求。
request->cancel();
run_cancel++;
AlibabaNls::NlsClient::getInstance()
->releaseFlowingSynthesizerRequest(request);
break;
}
pthread_mutex_unlock(&(cbParam.mtxWord));
Expand Down Expand Up @@ -1134,30 +1153,33 @@ void* pthreadFunc(void* arg) {
std::cout << "total text: " << text_str << std::endl;
for (std::vector<std::string>::const_iterator it = sentences.begin();
it != sentences.end(); ++it) {
std::cout << "sendText: " << *it << std::endl;
ret = request->sendText(it->c_str());
if (ret < 0) {
break;
}
if (sendFlushFlag) {
if (enableLongSilence) {
request->sendFlush("{\"enable_long_silence\":true}");
} else {
request->sendFlush();
if (isNotEmptyAndNotSpace(it->c_str())) {
std::cout << "sendText: " << *it << std::endl;
ret = request->sendText(it->c_str());
if (ret < 0) {
break;
}
if (sendFlushFlag) {
if (enableLongSilence) {
request->sendFlush("{\"enable_long_silence\":true}");
} else {
request->sendFlush();
}
}
usleep(500 * 1000);
}
usleep(500 * 1000);

if (!global_run) break;
} // for
if (ret < 0) {
std::cout << "sendText failed. pid:" << pthread_self() << std::endl;
std::cout << "sendText failed. pid:" << pthread_self()
<< ". ret: " << ret << std::endl;
const char* request_info = request->dumpAllInfo();
if (request_info) {
std::cout << " all info: " << request_info << std::endl;
}
AlibabaNls::NlsClient::getInstance()->releaseFlowingSynthesizerRequest(
request); // start()失败,释放request对象
request);
break;
}
}
Expand Down Expand Up @@ -1200,8 +1222,10 @@ void* pthreadFunc(void* arg) {
pthread_mutex_lock(&(cbParam.mtxWord));
if (ETIMEDOUT == pthread_cond_timedwait(&(cbParam.cvWord),
&(cbParam.mtxWord), &outtime)) {
std::cout << "stop timeout" << std::endl;
std::cout << "stop timeout, release this request" << std::endl;
pthread_mutex_unlock(&(cbParam.mtxWord));
AlibabaNls::NlsClient::getInstance()
->releaseFlowingSynthesizerRequest(request);
break;
}
pthread_mutex_unlock(&(cbParam.mtxWord));
Expand Down Expand Up @@ -1283,7 +1307,7 @@ void* pthreadLongConnectionFunc(void* arg) {
* 1. 创建流式文本语音合成FlowingSynthesizerRequest对象.
*
* 流式文本语音合成文档详见:
* https://help.aliyun.com/zh/isi/developer-reference/streaming-text-to-speech-synthesis/?spm=a2c4g.11186623.0.0.638b1f016dQylG
* https://help.aliyun.com/zh/isi/developer-reference/streaming-text-to-speech-synthesis
*/
AlibabaNls::FlowingSynthesizerRequest* request =
AlibabaNls::NlsClient::getInstance()->createFlowingSynthesizerRequest(
Expand Down Expand Up @@ -1475,19 +1499,21 @@ void* pthreadLongConnectionFunc(void* arg) {
std::cout << "total text: " << text_str << std::endl;
for (std::vector<std::string>::const_iterator it = sentences.begin();
it != sentences.end(); ++it) {
std::cout << "sendText: " << *it << std::endl;
ret = request->sendText(it->c_str());
if (ret < 0) {
break;
}
if (sendFlushFlag) {
if (enableLongSilence) {
request->sendFlush("{\"enable_long_silence\":true}");
} else {
request->sendFlush();
if (isNotEmptyAndNotSpace(it->c_str())) {
std::cout << "sendText: " << *it << std::endl;
ret = request->sendText(it->c_str());
if (ret < 0) {
break;
}
if (sendFlushFlag) {
if (enableLongSilence) {
request->sendFlush("{\"enable_long_silence\":true}");
} else {
request->sendFlush();
}
}
usleep(500 * 1000);
}
usleep(500 * 1000);

if (!global_run) break;
} // for
Expand Down
Loading