feat(overlay): update ASR loader
This commit is contained in:
@@ -27,18 +27,19 @@ impl AsrLoader {
|
|||||||
pub fn load(path: &Path) -> Result<Self> {
|
pub fn load(path: &Path) -> Result<Self> {
|
||||||
let content = std::fs::read_to_string(path)
|
let content = std::fs::read_to_string(path)
|
||||||
.with_context(|| format!("Failed to read ASR file: {:?}", path))?;
|
.with_context(|| format!("Failed to read ASR file: {:?}", path))?;
|
||||||
|
|
||||||
let data: AsrData = serde_json::from_str(&content)
|
let data: AsrData =
|
||||||
.with_context(|| "Failed to parse ASR JSON")?;
|
serde_json::from_str(&content).with_context(|| "Failed to parse ASR JSON")?;
|
||||||
|
|
||||||
Ok(Self { data })
|
Ok(Self { data })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_segment_at(&self, time_ms: f64) -> Option<&AsrSegment> {
|
pub fn get_segment_at(&self, time_ms: f64) -> Option<&AsrSegment> {
|
||||||
let time_sec = time_ms / 1000.0;
|
let time_sec = time_ms / 1000.0;
|
||||||
self.data.segments.iter().find(|seg| {
|
self.data
|
||||||
time_sec >= seg.start && time_sec < seg.end
|
.segments
|
||||||
})
|
.iter()
|
||||||
|
.find(|seg| time_sec >= seg.start && time_sec < seg.end)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_text_at(&self, time_ms: f64) -> Option<String> {
|
pub fn get_text_at(&self, time_ms: f64) -> Option<String> {
|
||||||
|
|||||||
Reference in New Issue
Block a user