@@ -228,22 +228,23 @@ export abstract class SynthesizeStream
228228
229229 protected async monitorMetrics ( ) {
230230 const startTime = process . hrtime . bigint ( ) ;
231- let audioDuration = 0 ;
231+ let audioDurationMs = 0 ;
232232 let ttfb : bigint = BigInt ( - 1 ) ;
233233 let requestId = '' ;
234234
235235 const emit = ( ) => {
236236 if ( this . #metricsPendingTexts. length ) {
237237 const text = this . #metricsPendingTexts. shift ( ) ! ;
238238 const duration = process . hrtime . bigint ( ) - startTime ;
239+ const roundedAudioDurationMs = Math . round ( audioDurationMs ) ;
239240 const metrics : TTSMetrics = {
240241 type : 'tts_metrics' ,
241242 timestamp : Date . now ( ) ,
242243 requestId,
243- ttfb : ttfb === BigInt ( - 1 ) ? - 1 : Math . trunc ( Number ( ttfb / BigInt ( 1000000 ) ) ) ,
244- duration : Math . trunc ( Number ( duration / BigInt ( 1000000 ) ) ) ,
244+ ttfbMs : ttfb === BigInt ( - 1 ) ? - 1 : Math . trunc ( Number ( ttfb / BigInt ( 1000000 ) ) ) ,
245+ durationMs : Math . trunc ( Number ( duration / BigInt ( 1000000 ) ) ) ,
245246 charactersCount : text . length ,
246- audioDuration ,
247+ audioDurationMs : roundedAudioDurationMs ,
247248 cancelled : this . abortController . signal . aborted ,
248249 label : this . #tts. label ,
249250 streamed : false ,
@@ -263,7 +264,7 @@ export abstract class SynthesizeStream
263264 ttfb = process . hrtime . bigint ( ) - startTime ;
264265 }
265266 // TODO(AJS-102): use frame.durationMs once available in rtc-node
266- audioDuration += audio . frame . samplesPerChannel / audio . frame . sampleRate ;
267+ audioDurationMs += ( audio . frame . samplesPerChannel / audio . frame . sampleRate ) * 1000 ;
267268 if ( audio . final ) {
268269 emit ( ) ;
269270 }
@@ -436,7 +437,7 @@ export abstract class ChunkedStream implements AsyncIterableIterator<Synthesized
436437
437438 protected async monitorMetrics ( ) {
438439 const startTime = process . hrtime . bigint ( ) ;
439- let audioDuration = 0 ;
440+ let audioDurationMs = 0 ;
440441 let ttfb : bigint = BigInt ( - 1 ) ;
441442 let requestId = '' ;
442443
@@ -446,7 +447,7 @@ export abstract class ChunkedStream implements AsyncIterableIterator<Synthesized
446447 if ( ttfb === BigInt ( - 1 ) ) {
447448 ttfb = process . hrtime . bigint ( ) - startTime ;
448449 }
449- audioDuration += audio . frame . samplesPerChannel / audio . frame . sampleRate ;
450+ audioDurationMs += ( audio . frame . samplesPerChannel / audio . frame . sampleRate ) * 1000 ;
450451 }
451452 this . output . close ( ) ;
452453
@@ -455,10 +456,10 @@ export abstract class ChunkedStream implements AsyncIterableIterator<Synthesized
455456 type : 'tts_metrics' ,
456457 timestamp : Date . now ( ) ,
457458 requestId,
458- ttfb : ttfb === BigInt ( - 1 ) ? - 1 : Math . trunc ( Number ( ttfb / BigInt ( 1000000 ) ) ) ,
459- duration : Math . trunc ( Number ( duration / BigInt ( 1000000 ) ) ) ,
459+ ttfbMs : ttfb === BigInt ( - 1 ) ? - 1 : Math . trunc ( Number ( ttfb / BigInt ( 1000000 ) ) ) ,
460+ durationMs : Math . trunc ( Number ( duration / BigInt ( 1000000 ) ) ) ,
460461 charactersCount : this . #text. length ,
461- audioDuration ,
462+ audioDurationMs : Math . round ( audioDurationMs ) ,
462463 cancelled : false , // TODO(AJS-186): support ChunkedStream with 1.0 - add this.abortController.signal.aborted here
463464 label : this . #tts. label ,
464465 streamed : false ,
0 commit comments