diff options
| author | Konstantin <const@const.me> | 2023-01-28 18:09:15 +0100 |
|---|---|---|
| committer | Konstantin <const@const.me> | 2023-01-28 18:09:15 +0100 |
| commit | 9253de193022e78cc4f91f4f1f7e14ba099e6388 (patch) | |
| tree | 41cf07bb396f892b362d4fffff20ab6711eec9c8 /Examples/main | |
| parent | cfd20a0f796ab6cc046b080bb7af8967cb7c361b (diff) | |
Diarize feature, initial version
Diffstat (limited to 'Examples/main')
| -rw-r--r-- | Examples/main/main.cpp | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/Examples/main/main.cpp b/Examples/main/main.cpp index ec95e13..3126381 100644 --- a/Examples/main/main.cpp +++ b/Examples/main/main.cpp @@ -65,7 +65,6 @@ namespace CHECK( results->getSize( length ) ); const whisper_params& params = *( (sPrintUserData*)user_data )->params; - // const std::vector<std::vector<float>>& pcmf32s = *( (sPrintUserData*)user_data )->pcmf32s; // print the last n_new segments const uint32_t s0 = length.countSegments - n_new; @@ -98,32 +97,28 @@ namespace } std::string speaker = ""; -#if 0 - if( params.diarize && pcmf32s.size() == 2 ) - { - const size_t n_samples = pcmf32s[ 0 ].size(); - const int64_t is0 = SourceAudio::sampleFromTimestamp( seg.time.begin, n_samples ); - const int64_t is1 = SourceAudio::sampleFromTimestamp( seg.time.end, n_samples ); - - double energy0 = 0.0f; - double energy1 = 0.0f; - for( int64_t j = is0; j < is1; j++ ) + if( params.diarize ) + { + eSpeakerChannel channel; + HRESULT hr = context->detectSpeaker( seg.time, channel ); + if( SUCCEEDED( hr ) && channel != eSpeakerChannel::NoStereoData ) { - energy0 += fabs( pcmf32s[ 0 ][ j ] ); - energy1 += fabs( pcmf32s[ 1 ][ j ] ); + using namespace std::string_literals; + switch( channel ) + { + case eSpeakerChannel::Unsure: + speaker = "(speaker ?)"s; + break; + case eSpeakerChannel::Left: + speaker = "(speaker 0)"s; + break; + case eSpeakerChannel::Right: + speaker = "(speaker 1)"; + break; + } } - - if( energy0 > 1.1 * energy1 ) - speaker = "(speaker 0)"; - else if( energy1 > 1.1 * energy0 ) - speaker = "(speaker 1)"; - else - speaker = "(speaker ?)"; - - //printf("is0 = %lld, is1 = %lld, energy0 = %f, energy1 = %f, %s\n", is0, is1, energy0, energy1, speaker.c_str()); } -#endif if( params.print_colors ) { |
