update speech util to support whisper stream (#657)

* update speech util to support whisper stream

* minor editing of span attributes

* more span attrs cleanup

---------

Co-authored-by: Dave Horton <daveh@beachdognet.com>
This commit is contained in:
Hoan Luu Huu
2024-02-23 02:17:29 +07:00
committed by GitHub
parent fc3655c9bd
commit 06b066a3f2
3 changed files with 18 additions and 9 deletions

View File

@@ -277,7 +277,6 @@ class TaskSay extends Task {
ep.once('playback-start', (evt) => { ep.once('playback-start', (evt) => {
this.logger.debug({evt}, 'got playback-start'); this.logger.debug({evt}, 'got playback-start');
if (this.otelSpan) { if (this.otelSpan) {
this.logger.debug({evt}, 'got playback-start');
this._addStreamingTtsAttributes(this.otelSpan, evt); this._addStreamingTtsAttributes(this.otelSpan, evt);
this.otelSpan.end(); this.otelSpan.end();
this.otelSpan = null; this.otelSpan = null;
@@ -341,11 +340,13 @@ class TaskSay extends Task {
for (const [key, value] of Object.entries(evt)) { for (const [key, value] of Object.entries(evt)) {
if (key.startsWith('variable_tts_')) { if (key.startsWith('variable_tts_')) {
let newKey = key.substring('variable_tts_'.length) let newKey = key.substring('variable_tts_'.length)
.replace('whisper_', 'whisper.')
.replace('elevenlabs_', 'elevenlabs.'); .replace('elevenlabs_', 'elevenlabs.');
if (spanMapping[newKey]) newKey = spanMapping[newKey]; if (spanMapping[newKey]) newKey = spanMapping[newKey];
attrs[newKey] = value; attrs[newKey] = value;
} }
} }
delete attrs['cache_filename']; //no value in adding this to the span
span.setAttributes(attrs); span.setAttributes(attrs);
} }
} }
@@ -355,6 +356,14 @@ const spanMapping = {
'elevenlabs.request_id': 'elevenlabs.req_id', 'elevenlabs.request_id': 'elevenlabs.req_id',
'elevenlabs.history_item_id': 'elevenlabs.item_id', 'elevenlabs.history_item_id': 'elevenlabs.item_id',
'elevenlabs.optimize_streaming_latency': 'elevenlabs.optimization', 'elevenlabs.optimize_streaming_latency': 'elevenlabs.optimization',
'elevenlabs.name_lookup_time_ms': 'name_lookup_ms',
'elevenlabs.connect_time_ms': 'connect_ms',
'elevenlabs.final_response_time_ms': 'final_response_ms',
'whisper.reported_latency_ms': 'whisper.latency_ms',
'whisper.request_id': 'whisper.req_id',
'whisper.name_lookup_time_ms': 'name_lookup_ms',
'whisper.connect_time_ms': 'connect_ms',
'whisper.final_response_time_ms': 'final_response_ms',
}; };
module.exports = TaskSay; module.exports = TaskSay;

14
package-lock.json generated
View File

@@ -15,7 +15,7 @@
"@jambonz/http-health-check": "^0.0.1", "@jambonz/http-health-check": "^0.0.1",
"@jambonz/mw-registrar": "^0.2.4", "@jambonz/mw-registrar": "^0.2.4",
"@jambonz/realtimedb-helpers": "^0.8.7", "@jambonz/realtimedb-helpers": "^0.8.7",
"@jambonz/speech-utils": "^0.0.41", "@jambonz/speech-utils": "^0.0.42",
"@jambonz/stats-collector": "^0.1.9", "@jambonz/stats-collector": "^0.1.9",
"@jambonz/time-series": "^0.2.8", "@jambonz/time-series": "^0.2.8",
"@jambonz/verb-specifications": "^0.0.53", "@jambonz/verb-specifications": "^0.0.53",
@@ -3468,9 +3468,9 @@
} }
}, },
"node_modules/@jambonz/speech-utils": { "node_modules/@jambonz/speech-utils": {
"version": "0.0.41", "version": "0.0.42",
"resolved": "https://registry.npmjs.org/@jambonz/speech-utils/-/speech-utils-0.0.41.tgz", "resolved": "https://registry.npmjs.org/@jambonz/speech-utils/-/speech-utils-0.0.42.tgz",
"integrity": "sha512-i07b4usrw5olnqU0WCRbTVzWauvA2IEfpFeKfdAxeTZ8VbbpKeTOTCfEpz4DlkOWGcR8kWrdM9DWbK4fjv/t1w==", "integrity": "sha512-ROYin2JqV41Q9T14SOpaXBAvalkOAiMGzCxG9Q1d3XCvxDQ/QQXHbZeFdd9cc64eq4OJNtd9lxmnCS+DSPNuXQ==",
"dependencies": { "dependencies": {
"@aws-sdk/client-polly": "^3.496.0", "@aws-sdk/client-polly": "^3.496.0",
"@aws-sdk/client-sts": "^3.496.0", "@aws-sdk/client-sts": "^3.496.0",
@@ -14112,9 +14112,9 @@
} }
}, },
"@jambonz/speech-utils": { "@jambonz/speech-utils": {
"version": "0.0.41", "version": "0.0.42",
"resolved": "https://registry.npmjs.org/@jambonz/speech-utils/-/speech-utils-0.0.41.tgz", "resolved": "https://registry.npmjs.org/@jambonz/speech-utils/-/speech-utils-0.0.42.tgz",
"integrity": "sha512-i07b4usrw5olnqU0WCRbTVzWauvA2IEfpFeKfdAxeTZ8VbbpKeTOTCfEpz4DlkOWGcR8kWrdM9DWbK4fjv/t1w==", "integrity": "sha512-ROYin2JqV41Q9T14SOpaXBAvalkOAiMGzCxG9Q1d3XCvxDQ/QQXHbZeFdd9cc64eq4OJNtd9lxmnCS+DSPNuXQ==",
"requires": { "requires": {
"@aws-sdk/client-polly": "^3.496.0", "@aws-sdk/client-polly": "^3.496.0",
"@aws-sdk/client-sts": "^3.496.0", "@aws-sdk/client-sts": "^3.496.0",

View File

@@ -31,7 +31,7 @@
"@jambonz/http-health-check": "^0.0.1", "@jambonz/http-health-check": "^0.0.1",
"@jambonz/mw-registrar": "^0.2.4", "@jambonz/mw-registrar": "^0.2.4",
"@jambonz/realtimedb-helpers": "^0.8.7", "@jambonz/realtimedb-helpers": "^0.8.7",
"@jambonz/speech-utils": "^0.0.41", "@jambonz/speech-utils": "^0.0.42",
"@jambonz/stats-collector": "^0.1.9", "@jambonz/stats-collector": "^0.1.9",
"@jambonz/time-series": "^0.2.8", "@jambonz/time-series": "^0.2.8",
"@jambonz/verb-specifications": "^0.0.53", "@jambonz/verb-specifications": "^0.0.53",