@@ -53,28 +53,26 @@ public List<SileroSpeechSegment> GetSpeechSegmentList(FileInfo wavFile)
5353 {
5454 Reset ( ) ;
5555
56- using ( var audioFile = new AudioFileReader ( wavFile . FullName ) )
57- {
58- List < float > speechProbList = new List < float > ( ) ;
59- this . _audioLengthSamples = ( int ) ( audioFile . Length / 2 ) ;
60- float [ ] buffer = new float [ this . _windowSizeSample ] ;
61-
62- while ( audioFile . Read ( buffer , 0 , buffer . Length ) > 0 )
63- {
64- float speechProb = _model . Call ( new [ ] { buffer } , _samplingRate ) [ 0 ] ;
65- speechProbList . Add ( speechProb ) ;
66- }
56+ using var audioFile = new AudioFileReader ( wavFile . FullName ) ;
57+ List < float > speechProbList = [ ] ;
58+ this . _audioLengthSamples = ( int ) ( audioFile . Length / 2 ) ;
59+ float [ ] buffer = new float [ this . _windowSizeSample ] ;
6760
68- return CalculateProb ( speechProbList ) ;
61+ while ( audioFile . Read ( buffer , 0 , buffer . Length ) > 0 )
62+ {
63+ float speechProb = _model . Call ( [ buffer ] , _samplingRate ) [ 0 ] ;
64+ speechProbList . Add ( speechProb ) ;
6965 }
66+
67+ return CalculateProb ( speechProbList ) ;
7068 }
7169
7270 private List < SileroSpeechSegment > CalculateProb ( List < float > speechProbList )
7371 {
74- List < SileroSpeechSegment > result = new List < SileroSpeechSegment > ( ) ;
72+ List < SileroSpeechSegment > result = [ ] ;
7573 bool triggered = false ;
7674 int tempEnd = 0 , prevEnd = 0 , nextStart = 0 ;
77- SileroSpeechSegment segment = new SileroSpeechSegment ( ) ;
75+ SileroSpeechSegment segment = new ( ) ;
7876
7977 for ( int i = 0 ; i < speechProbList . Count ; i ++ )
8078 {
@@ -164,7 +162,8 @@ private List<SileroSpeechSegment> CalculateProb(List<float> speechProbList)
164162
165163 if ( segment . StartOffset != null && ( _audioLengthSamples - segment . StartOffset ) > _minSpeechSamples )
166164 {
167- segment . EndOffset = _audioLengthSamples ;
165+ //segment.EndOffset = _audioLengthSamples;
166+ segment . EndOffset = speechProbList . Count * _windowSizeSample ;
168167 result . Add ( segment ) ;
169168 }
170169
@@ -182,7 +181,7 @@ private List<SileroSpeechSegment> CalculateProb(List<float> speechProbList)
182181 int silenceDuration = nextItem . StartOffset . Value - item . EndOffset . Value ;
183182 if ( silenceDuration < 2 * _speechPadSamples )
184183 {
185- item . EndOffset = item . EndOffset + ( silenceDuration / 2 ) ;
184+ item . EndOffset += ( silenceDuration / 2 ) ;
186185 nextItem . StartOffset = Math . Max ( 0 , nextItem . StartOffset . Value - ( silenceDuration / 2 ) ) ;
187186 }
188187 else
@@ -200,9 +199,9 @@ private List<SileroSpeechSegment> CalculateProb(List<float> speechProbList)
200199 return MergeListAndCalculateSecond ( result , _samplingRate ) ;
201200 }
202201
203- private List < SileroSpeechSegment > MergeListAndCalculateSecond ( List < SileroSpeechSegment > original , int samplingRate )
202+ private static List < SileroSpeechSegment > MergeListAndCalculateSecond ( List < SileroSpeechSegment > original , int samplingRate )
204203 {
205- List < SileroSpeechSegment > result = new List < SileroSpeechSegment > ( ) ;
204+ List < SileroSpeechSegment > result = [ ] ;
206205 if ( original == null || original . Count == 0 )
207206 {
208207 return result ;
@@ -216,7 +215,10 @@ private List<SileroSpeechSegment> MergeListAndCalculateSecond(List<SileroSpeechS
216215 for ( int i = 1 ; i < original . Count ; i ++ )
217216 {
218217 SileroSpeechSegment segment = original [ i ] ;
218+ if ( i == 235 )
219+ {
219220
221+ }
220222 if ( segment . StartOffset > right )
221223 {
222224 result . Add ( new SileroSpeechSegment ( left , right ,
@@ -242,7 +244,7 @@ private List<SileroSpeechSegment> MergeListAndCalculateSecond(List<SileroSpeechS
242244 return result ;
243245 }
244246
245- private float CalculateSecondByOffset ( int offset , int samplingRate )
247+ private static float CalculateSecondByOffset ( int offset , int samplingRate )
246248 {
247249 float secondValue = offset * 1.0f / samplingRate ;
248250 return ( float ) Math . Floor ( secondValue * 1000.0f ) / 1000.0f ;
0 commit comments