| 65 | } |
| 66 | |
| 67 | func (s *liveTranscriptionSession) Close() error { |
| 68 | s.closeOnce.Do(func() { |
| 69 | err := s.stream.CloseSend() |
| 70 | select { |
| 71 | case <-s.recvDone: |
| 72 | case <-time.After(liveCloseDrainTimeout): |
| 73 | xlog.Warn("live transcription: backend did not finalize in time; cancelling stream") |
| 74 | s.cancel() |
| 75 | <-s.recvDone |
| 76 | } |
| 77 | s.cancel() |
| 78 | if err == nil { |
| 79 | err = s.recvErr |
| 80 | } |
| 81 | s.closeErr = err |
| 82 | s.trace.record(err) |
| 83 | }) |
| 84 | return s.closeErr |
| 85 | } |
| 86 | |
| 87 | // liveSampleRate is the PCM rate of a live transcription session, fixed by |
| 88 | // the session config sent in ModelTranscriptionLive. |