【发布时间】:2019-05-27 06:44:51
【问题描述】:
我已经使用另一个 API 和 IBM Watson Speech to Text 服务 API 在 c++ 中开发了一个流式语音识别应用程序。
在这两个程序中,我使用的是包含此音频的同一文件
周日,一连串严重的雷暴席卷科罗拉多州,导致几起龙卷风降落
此文件的大小为 641,680 字节,我一次将 100,000 字节(最大) 块发送到 Speech to text 服务器。
现在,使用其他 API,我可以将所有内容作为一个整体进行识别。使用 IBM Watson API 我做不到。这是我所做的:
- 连接到 IBM Watson Web 服务器(语音转文本 API)
- 发送起始帧
{"action":"start","content-type":"audio/mulaw;rate=8000"} - 发送二进制 100,000 字节
- 发送停止帧
{"action":"stop"} - ...重复二进制并停止直到最后一个字节。
IBM Watson Speech API 只能单独识别块
例如
几场龙卷风降落
一道强雷
席卷科罗拉多
周日
这似乎是单个块的输出以及块划分之间的单词(例如,这里的“thunderstorm”部分出现在块的末尾,部分出现在下一个块的开头) 因此被错误识别或丢弃。
我做错了什么?
编辑(我正在使用 c++ 和 websocket 接口的 boost 库)
//Do the websocket handshake
void IbmWebsocketSession::on_ssl_handshake(beast::error_code ec) {
auto mToken = mSttServiceObject->GetToken(); // Get the authentication token
//Complete the websocket handshake and call back the "send_start" function
mWebSocket.async_handshake_ex(mHost, mUrlEndpoint, [mToken](request_type& reqHead) {reqHead.insert(http::field::authorization,mToken);},
bind(&IbmWebsocketSession::send_start, shared_from_this(), placeholders::_1));
}
//Sent the start frame
void IbmWebsocketSession::send_start(beast::error_code ec) {
//Send the START_FRAME and call back the "read_resp" function to receive the "state: listening" message
mWebSocket.async_write(net::buffer(START_FRAME),
bind(&IbmWebsocketSession::read_resp, shared_from_this(), placeholders::_1, placeholders::_2));
}
//Sent the binary data
void IbmWebsocketSession::send_binary(beast::error_code ec) {
streamsize bytes_read = mFilestream.rdbuf()->sgetn(&chunk[0], chunk.size()); //gets the binary data chunks from a file (which is being written at run time
// Send binary data
if (bytes_read > mcMinsize) { //Minimum size defined by IBM is 100 bytes.
// If chunk size is greater than 100 bytes, then send the data and then callback "send_stop" function
mWebSocket.binary(true);
/**********************************************************************
* Wait a second before writing the next chunk.
**********************************************************************/
this_thread::sleep_for(chrono::seconds(1));
mWebSocket.async_write(net::buffer(&chunk[0], bytes_read),
bind(&IbmWebsocketSession::send_stop, shared_from_this(), placeholders::_1));
} else { //If chunk size is less than 100 bytes, then DO NOT send the data only call "send_stop" function
shared_from_this()->send_stop(ec);
}
}
void IbmWebsocketSession::send_stop(beast::error_code ec) {
mWebSocket.binary(false);
/*****************************************************************
* Send the Stop message
*****************************************************************/
mWebSocket.async_write(net::buffer(mTextStop),
bind(&IbmWebsocketSession::read_resp, shared_from_this(), placeholders::_1, placeholders::_2));
}
void IbmWebsocketSession::read_resp(beast::error_code ec, size_t bytes_transferred) {
boost::ignore_unused(bytes_transferred);
if(mWebSocket.is_open())
{
// Read the websocket response and call back the "display_buffer" function
mWebSocket.async_read(mBuffer, bind(&IbmWebsocketSession::display_buffer, shared_from_this(),placeholders::_1));
}
else
cerr << "Error: " << e->what() << endl;
}
void IbmWebsocketSession::display_buffer(beast::error_code ec) {
/*****************************************************************
* Get the buffer into stringstream
*****************************************************************/
msWebsocketResponse << beast::buffers(mBuffer.data());
mResponseTranscriptIBM = ParseTranscript(); //Parse the response transcript
mBuffer.consume(mBuffer.size()); //Clear the websocket buffer
if ("Listening" == mResponseTranscriptIBM && true != mSttServiceObject->IsGstFileWriteDone()) { // IsGstFileWriteDone -> checks if the user has stopped speaking
shared_from_this()->send_binary(ec);
} else {
shared_from_this()->close_websocket(ec, 0);
}
}
【问题讨论】:
-
显示你用过的代码——比文字更好
-
@data_henrik 好吧!我可以分享代码,但我认为这不是编码问题。我的猜测是,要么这是 IBM API 的功能,要么我 在逻辑上 做错了什么。尽管我必须进行一些更改以遵循我组织的政策。所以编辑可能需要一些时间。
标签: ibm-cloud speech-recognition ibm-watson speech-to-text