@@ -136,7 +136,7 @@ export abstract class SynthesizeStream
136136 const metrics : TTSMetrics = {
137137 timestamp : Date . now ( ) ,
138138 requestId,
139- ttfb : Math . trunc ( Number ( ttfb ! / BigInt ( 1000000 ) ) ) ,
139+ ttfb : Math . trunc ( Number ( ( ttfb || BigInt ( 0 ) ) / BigInt ( 1000000 ) ) ) ,
140140 duration : Math . trunc ( Number ( duration / BigInt ( 1000000 ) ) ) ,
141141 charactersCount : text . length ,
142142 audioDuration,
@@ -257,13 +257,13 @@ export abstract class ChunkedStream implements AsyncIterableIterator<Synthesized
257257 protected async monitorMetrics ( ) {
258258 const startTime = process . hrtime . bigint ( ) ;
259259 let audioDuration = 0 ;
260- let ttfb : bigint | undefined ;
260+ let ttfb : bigint = BigInt ( - 1 ) ;
261261 let requestId = '' ;
262262
263263 for await ( const audio of this . queue ) {
264264 this . output . put ( audio ) ;
265265 requestId = audio . requestId ;
266- if ( ! ttfb ) {
266+ if ( ttfb === BigInt ( - 1 ) ) {
267267 ttfb = process . hrtime . bigint ( ) - startTime ;
268268 }
269269 audioDuration += audio . frame . samplesPerChannel / audio . frame . sampleRate ;
@@ -274,7 +274,7 @@ export abstract class ChunkedStream implements AsyncIterableIterator<Synthesized
274274 const metrics : TTSMetrics = {
275275 timestamp : Date . now ( ) ,
276276 requestId,
277- ttfb : Math . trunc ( Number ( ttfb ! / BigInt ( 1000000 ) ) ) ,
277+ ttfb : ttfb === BigInt ( - 1 ) ? - 1 : Math . trunc ( Number ( ttfb / BigInt ( 1000000 ) ) ) ,
278278 duration : Math . trunc ( Number ( duration / BigInt ( 1000000 ) ) ) ,
279279 charactersCount : this . #text. length ,
280280 audioDuration,
0 commit comments