Skip to content

Commit

Permalink
encode and send voice only if voice activated
Browse files Browse the repository at this point in the history
  • Loading branch information
zhang-ray committed Oct 31, 2018
1 parent d9d532a commit 17f243e
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions client_essential/Worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,18 +255,24 @@ void Worker::syncStart(const std::string &host,
static SuckAudioVolume sav;
micVolumeReporter_(sav.calculate(denoisedBuffer));
}

auto haveVoice = (1==WebRtcVad_Process(vad, sampleRate, denoisedBuffer.data(), sampleRate/100));
if (vadReporter_){
vadReporter_(1==WebRtcVad_Process(vad, sampleRate, denoisedBuffer.data(), sampleRate/100));
vadReporter_(haveVoice);
}

std::vector<char> outData;
auto retEncode = encoder->encode(needAec_? tobeSend: denoisedBuffer, outData);
if (!retEncode){
std::cout << retEncode.message() << std::endl;
break;
}

client.send(NetPacket(NetPacket::PayloadType::AudioMessage, outData));
//// encode and send voice only if voice activated
if (haveVoice){
std::vector<char> outData;
auto retEncode = encoder->encode(needAec_? tobeSend: denoisedBuffer, outData);
if (!retEncode){
std::cout << retEncode.message() << std::endl;
break;
}

client.send(NetPacket(NetPacket::PayloadType::AudioMessage, outData));
}



Expand Down

0 comments on commit 17f243e

Please sign in to comment.