Restructure to minimize the number of unsafe calls in VAD code
This commit is contained in:
parent
ef095214b7
commit
ac6b01dd91
1 changed files with 10 additions and 9 deletions
|
|
@ -250,9 +250,13 @@ impl WhisperVadSegments {
|
|||
self.segment_count
|
||||
}
|
||||
|
||||
pub fn index_in_bounds(&self, idx: c_int) -> bool {
|
||||
idx < 0 || idx > self.segment_count
|
||||
}
|
||||
|
||||
/// Return the start timestamp of this segment in centiseconds (10s of milliseconds).
|
||||
pub fn get_segment_start_timestamp(&self, idx: c_int) -> Option<f32> {
|
||||
if idx < 0 || idx > self.segment_count {
|
||||
if self.index_in_bounds(idx) {
|
||||
None
|
||||
} else {
|
||||
Some(unsafe { whisper_vad_segments_get_segment_t0(self.ptr, idx) })
|
||||
|
|
@ -261,7 +265,7 @@ impl WhisperVadSegments {
|
|||
|
||||
/// Return the end timestamp of this segment in centiseconds (10s of milliseconds).
|
||||
pub fn get_segment_end_timestamp(&self, idx: c_int) -> Option<f32> {
|
||||
if idx < 0 || idx > self.segment_count {
|
||||
if self.index_in_bounds(idx) {
|
||||
None
|
||||
} else {
|
||||
Some(unsafe { whisper_vad_segments_get_segment_t1(self.ptr, idx) })
|
||||
|
|
@ -269,13 +273,10 @@ impl WhisperVadSegments {
|
|||
}
|
||||
|
||||
pub fn get_segment(&self, idx: c_int) -> Option<WhisperVadSegment> {
|
||||
if idx < 0 || idx > self.segment_count {
|
||||
None
|
||||
} else {
|
||||
let start = unsafe { whisper_vad_segments_get_segment_t0(self.ptr, self.iter_idx) };
|
||||
let end = unsafe { whisper_vad_segments_get_segment_t1(self.ptr, self.iter_idx) };
|
||||
Some(WhisperVadSegment { start, end })
|
||||
}
|
||||
let start = self.get_segment_start_timestamp(idx)?;
|
||||
let end = self.get_segment_end_timestamp(idx)?;
|
||||
|
||||
Some(WhisperVadSegment { start, end })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue