|
34 | 34 | CppTTSFree func(ptr uintptr) |
35 | 35 | CppTTSSetVoice func(name string) int |
36 | 36 | CppTTSSetVoiceFile func(path string, refText string) int |
| 37 | + |
| 38 | + // Word-level timestamp accessors (session-based, per-segment) |
| 39 | + CppGetWordCount func(segI int) int |
| 40 | + CppGetWordText func(segI int, wordI int) string |
| 41 | + CppGetWordT0 func(segI int, wordI int) int64 |
| 42 | + CppGetWordT1 func(segI int, wordI int) int64 |
| 43 | + |
| 44 | + // Parakeet-specific word accessors (global, no segment index) |
| 45 | + CppGetParakeetWordCount func() int |
| 46 | + CppGetParakeetWordText func(wordI int) string |
| 47 | + CppGetParakeetWordT0 func(wordI int) int64 |
| 48 | + CppGetParakeetWordT1 func(wordI int) int64 |
37 | 49 | ) |
38 | 50 |
|
39 | 51 | type CrispASR struct { |
@@ -290,10 +302,36 @@ func (w *CrispASR) AudioTranscription(ctx context.Context, opts *pb.TranscriptRe |
290 | 302 | // IDs, so Tokens is left empty. |
291 | 303 | txt := strings.ToValidUTF8(strings.Clone(CppGetSegmentText(i)), "�") |
292 | 304 |
|
| 305 | + // Populate word-level timestamps. Try session-based functions first |
| 306 | + // (per-segment); fall back to parakeet-specific functions (global word |
| 307 | + // list with no segment index — only populated on the first segment to |
| 308 | + // avoid duplication). |
| 309 | + words := []*pb.TranscriptWord{} |
| 310 | + wordCount := CppGetWordCount(i) |
| 311 | + if wordCount == 0 && i == 0 { |
| 312 | + wordCount = CppGetParakeetWordCount() |
| 313 | + for j := 0; j < wordCount; j++ { |
| 314 | + words = append(words, &pb.TranscriptWord{ |
| 315 | + Start: CppGetParakeetWordT0(j) * (10000000), |
| 316 | + End: CppGetParakeetWordT1(j) * (10000000), |
| 317 | + Text: strings.ToValidUTF8(strings.Clone(CppGetParakeetWordText(j)), "�"), |
| 318 | + }) |
| 319 | + } |
| 320 | + } else { |
| 321 | + for j := 0; j < wordCount; j++ { |
| 322 | + words = append(words, &pb.TranscriptWord{ |
| 323 | + Start: CppGetWordT0(i, j) * (10000000), |
| 324 | + End: CppGetWordT1(i, j) * (10000000), |
| 325 | + Text: strings.ToValidUTF8(strings.Clone(CppGetWordText(i, j)), "�"), |
| 326 | + }) |
| 327 | + } |
| 328 | + } |
| 329 | + |
293 | 330 | segment := &pb.TranscriptSegment{ |
294 | 331 | Id: int32(i), |
295 | 332 | Text: txt, |
296 | 333 | Start: s, End: t, |
| 334 | + Words: words, |
297 | 335 | } |
298 | 336 |
|
299 | 337 | segments = append(segments, segment) |
|
0 commit comments