Skip to content

Commit 4a40705

Browse files
authored
Merge pull request #154 from babblevoice/transcribe-client-and-local-close-normalise
Add channel-client transcribe() + normalise local close() args (3.2.3)
2 parents 08fdd19 + e1647e6 commit 4a40705

4 files changed

Lines changed: 33 additions & 3 deletions

File tree

index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,16 @@ class projectrtp {
471471
/* ensure we are identicle to the node version of this object */
472472
chan.openchannel = this.openchannel.bind( this )
473473

474+
/* The remote (server.js) channel close() takes an options object
475+
({ timeout }); the local Rust napi close() takes an optional reason
476+
string and returns a bool. Normalise so callers can hand the same
477+
options object to either transport - callmanager calls
478+
close( { timeout } ) regardless of whether the channel is local or
479+
remote, and the bare object would otherwise fail napi's
480+
String conversion. */
481+
const napiclose = chan.close.bind( chan )
482+
chan.close = ( options ) => napiclose( "string" === typeof options ? options : undefined )
483+
474484
/* Wrap the Rust `createReadStream(opts, cb)` napi method so JS gets a
475485
standard Node `Readable` — pipeable into fs.createWriteStream,
476486
WebSocket, fetch bodies, any transform stream, etc.

lib/server.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,26 @@ class channel {
561561
return true
562562
}
563563

564+
/**
565+
@summary Start live transcription on the channel. The command itself is a no-op
566+
at the channel level - it is consumed by the node's pre hook, which binds the
567+
token to this channel and taps its audio (getchannel() + createReadStream) to
568+
stream speech-to-text.
569+
@param { Object } options
570+
@param { string } options.token - identifier the audio-tap consumer binds to
571+
@param { string } [ options.engine ] - STT engine
572+
@param { string } [ options.language ] - BCP-47 hint
573+
@param { string } [ options.model ] - engine model override
574+
@returns { boolean }
575+
*/
576+
transcribe( options ) {
577+
this._write( {
578+
"channel": "transcribe",
579+
options
580+
} )
581+
return true
582+
}
583+
564584
/**
565585
* We have received the open confirm message so we should action it
566586
* @private

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@babblevoice/projectrtp",
3-
"version": "3.2.2",
3+
"version": "3.2.3",
44
"description": "A scalable Node addon RTP server",
55
"main": "index.js",
66
"directories": {

0 commit comments

Comments
 (0)