wip: implemented listen, transcribe, play

This commit is contained in:
Dave Horton
2020-01-17 09:15:23 -05:00
parent 1a656f3f0e
commit 0d4c1d9d8c
24 changed files with 688 additions and 108 deletions

View File

@@ -32,5 +32,23 @@
"Endpoint": "endpoint",
"StableCall": "stable-call",
"UnansweredCall": "unanswered-call"
},
"TranscriptionEvents": {
"Transcription": "google_transcribe::transcription",
"EndOfUtterance": "google_transcribe::end_of_utterance",
"NoAudioDetected": "google_transcribe::no_audio_detected",
"MaxDurationExceeded": "google_transcribe::max_duration_exceeded"
},
"ListenEvents": {
"Connect": "mod_audio_fork::connect",
"ConnectFailure": "mod_audio_fork::connect_failed",
"Transcription": "mod_audio_fork::transcription",
"Transfer": "mod_audio_fork::transcription",
"PlayAudio": "mod_audio_fork::play_audio",
"KillAudio": "mod_audio_fork::kill_audio",
"Disconnect": "mod_audio_fork::disconnect",
"Error": "mod_audio_fork::error",
"BufferOverrun": "mod_audio_fork::buffer_overrun",
"JsonMessage": "mod_audio_fork::json"
}
}

View File

@@ -0,0 +1,33 @@
function normalizeJambones(logger, obj) {
logger.debug(`normalizeJambones: ${JSON.stringify(obj)}`);
if (!Array.isArray(obj)) throw new Error('invalid JSON: jambones docs must be array');
const document = [];
for (const tdata of obj) {
if (typeof tdata !== 'object') throw new Error('invalid JSON: jambones docs must be array of objects');
if (Object.keys(tdata).length === 1) {
// {'say': {..}}
logger.debug(`pushing ${JSON.stringify(tdata)}`);
document.push(tdata);
}
else if ('verb' in tdata) {
// {verb: 'say', text: 'foo..bar'..}
const name = tdata.verb;
const o = {};
Object.keys(tdata)
.filter((k) => k !== 'verb')
.forEach((k) => o[k] = tdata[k]);
const o2 = {};
o2[name] = o;
document.push(o2);
}
else {
logger.info(tdata, `invalid JSON: invalid verb form, numkeys ${Object.keys(tdata).length}`);
throw new Error('invalid JSON: invalid verb form');
}
}
logger.debug(`returning document with ${document.length} tasks`);
return document;
}
module.exports = normalizeJambones;

View File

@@ -11,8 +11,8 @@ function hooks(logger, callAttributes) {
url,
method,
json: true,
qs: 'GET' === method ? params : null,
body: 'POST' === method ? params : null
qs: 'GET' === method ? params : callAttributes,
body: 'POST' === method ? opts : null
};
logger.debug(`${method} ${url} sending ${JSON.stringify(obj)}`);
return new Promise((resolve, reject) => {

View File

@@ -0,0 +1,55 @@
const Emitter = require('events');
const {CallStatus} = require('./constants');
class SingleDialer extends Emitter {
constructor(logger, opts) {
super();
this.logger = logger;
this.cs = opts.cs;
this.ms = opts.ms;
}
get callState() {
return this._callState;
}
/**
* launch the outdial
*/
exec() {
}
/**
* kill the call in progress, or stable dialog, whichever
*/
async kill() {
}
/**
* execute a jambones application on this call / endpoint
* @param {*} jambones document
*/
async runApp(document) {
}
async _createEndpoint() {
}
async _outdial() {
}
}
function placeOutdial(logger, opts) {
const singleDialer = new SingleDialer(logger, opts);
singleDialer.exec();
return singleDialer;
}
module.exports = placeOutdial;