语音实现如下:- 您的调制解调器总共注册 5 个设备。音频通过名为“Huawei Mobile Connect - 应用程序接口”的串行端口发送。
语音(输入|输出)数据格式:
wFormatTag = WAVE_FORMAT_PCM;
nChannels = 1;
nSamplesPerSec = 8000;
nAvgBytesPerSec = 16000;
nBlockAlign = 2;
wBitsPerSample = 16;
cbSize = 0;
ReadFile 或 WriteFile 操作中语音数据的块大小(对于 COM 端口)必须设置为 320 字节。在每个 ReadFile 之后必须是 WriteFile 操作(在其他选择缓冲区将溢出,调制解调器将在一段时间后重新启动)。示例:
// BlockSize - size of buff for wave in|out operations (in my case 320*4 bytes)
while (!bAllRead) {
if (cInfo->hCom == INVALID_HANDLE_VALUE) {
SetVoiceClosed(cInfo);//exit from thread
return 0;
}
BOOL isRead = ReadFile(cInfo->hCom, cInfo->Header[counter].lpData + currBlocLength, 320, &nActualRead, &cInfo->o);
if (isRead || (GetLastError() == ERROR_IO_PENDING && GetOverlappedResult(cInfo->hCom, &cInfo->o, &nActualRead, TRUE))) {
if (nActualRead > 0) {
// обратка
nActualWrite = 0;
int nActualWriteAll = 0;
BOOL isWrite = WriteFile(cInfo->hCom, CurrBuffPtr + currBlocLength, nActualRead, &nActualWrite, &cInfo->oVoiceOut);
while (isWrite || (GetLastError() == ERROR_IO_PENDING && GetOverlappedResult(cInfo->hCom, &cInfo->oVoiceOut, &nActualWrite, TRUE))) {
nActualWriteAll += nActualWrite;
if (nActualWriteAll >= nActualRead)
break;
}
currBlocLength += nActualRead;
if (currBlocLength >= BlockSize)
bAllRead = true;
}
else {
Sleep(25);// wait for voice data (resync)
PurgeComm(cInfo->hCom, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);
}
}
else {
bAllRead = true;// there are no active call
PurgeComm(cInfo->hCom, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);
}
}
类似的东西)))。我在 Internet 上找不到任何有用的信息,所以所有这些建议都是基于我的实验。我希望这很有用。
PS:希望wave in|out 操作不会对你造成问题。
PS2:对不起我的英语,我来自乌克兰。