src/toolbars/TranscriptionToolBar.cpp
//This automates selection through a selected region,
//selecting its best guess for words and creating labels at those points.
This automates selection through a selected region,
selecting its best guess for words and creating labels at those points.
This automates selection through a selected region selecting its best guess for words and creating labels at those points .
void TranscriptionToolBar::OnAutomateSelection(wxCommandEvent & WXUNUSED(event))
{
   auto gAudioIO = AudioIOBase::Get();
   if (gAudioIO->IsBusy())
   {
      SetButton(false,mButtons[TTB_EndOff]);
      return;
   }
   wxBusyCursor busy;
   mVk->AdjustThreshold(GetSensitivity());
   TrackList *tl = &TrackList::Get( mProject );
   if(auto wt = *tl->Any<const WaveTrack>().begin()) {
      sampleCount start, len;
      GetSamples(wt, &start, &len);
      if(len == 0)
      {
         len = start;
         start = 0;
      }
      sampleCount lastlen = 0;
      double newStartPos, newEndPos;
      int minWordSize = (int)(wt->GetRate() * .05);
      while(len > 0 && lastlen != len)
      {
         lastlen = len;
         auto newStart = mVk->OnForward(*wt, start, len);
         if( newStart==start)
            break;
         len -= (newStart - start);
         len -= minWordSize;
         auto newEnd   =
         mVk->OffForward(*wt, newStart + minWordSize, len);
         if(newEnd == (newStart + minWordSize))
            break;
         len -= (newEnd - newStart);
         newStartPos = newStart.as_double() / wt->GetRate();
         newEndPos = newEnd.as_double() / wt->GetRate();
         start = newEnd;
         DoAddLabel(mProject, SelectedRegion(newStartPos, newEndPos));
      ProjectWindow::Get( mProject ).RedrawProject();
      }
      SetButton(false, mButtons[TTB_AutomateSelection]);
   }
}
void TranscriptionToolBar :: OnAutomateSelection ( wxCommandEvent & WXUNUSED ( event ) ) { auto gAudioIO = AudioIOBase :: Get ( ) ; if ( gAudioIO -> IsBusy ( ) ) { SetButton ( false , mButtons [ TTB_EndOff ] ) ; return ; } wxBusyCursor busy ; mVk -> AdjustThreshold ( GetSensitivity ( ) ) ; TrackList * tl = & TrackList :: Get ( mProject ) ; if ( auto wt = * tl -> Any < const WaveTrack > ( ) . begin ( ) ) { sampleCount start , len ; GetSamples ( wt , & start , & len ) ; if ( len == 0 ) { len = start ; start = 0 ; } sampleCount lastlen = 0 ; double newStartPos , newEndPos ; int minWordSize = ( int ) ( wt -> GetRate ( ) * .05 ) ; while ( len > 0 && lastlen != len ) { lastlen = len ; auto newStart = mVk -> OnForward ( * wt , start , len ) ; if ( newStart == start ) break ; len -= ( newStart - start ) ; len -= minWordSize ; auto newEnd = mVk -> OffForward ( * wt , newStart + minWordSize , len ) ; if ( newEnd == ( newStart + minWordSize ) ) break ; len -= ( newEnd - newStart ) ; newStartPos = newStart . as_double ( ) / wt -> GetRate ( ) ; newEndPos = newEnd . as_double ( ) / wt -> GetRate ( ) ; start = newEnd ; DoAddLabel ( mProject , SelectedRegion ( newStartPos , newEndPos ) ) ; ProjectWindow :: Get ( mProject ) . RedrawProject ( ) ; } SetButton ( false , mButtons [ TTB_AutomateSelection ] ) ; } }
This automates selection through a selected region,
selecting its best guess for words and creating labels at those points.
This automates selection through a selected region selecting its best guess for words and creating labels at those points .
//If IO is busy, abort immediately //Adjust length to end if selection is null //This is the minimum word size in samples (.05 is 50 ms) //Continue until we have processed the entire //region, or we are making no progress. //JKC: If no start found then don't add any labels. //Adjust len by the NEW start position //Adjust len by the minimum word size //OK, now we have found a NEW starting point.  A 'word' should be at least //50 ms long, so jump ahead minWordSize //If newEnd didn't move, we should give up, because // there isn't another end before the end of the selection. //Adjust len by the NEW word end //Calculate the start and end of the words, in seconds //Increment