@fonos/voice
Advanced tools
Comparing version 0.0.23 to 0.0.24
@@ -7,5 +7,7 @@ import Verb from './verb'; | ||
offset?: number; | ||
format?: string; | ||
} | ||
declare class Record extends Verb { | ||
constructor(channel: any); | ||
constructor(channel: any, config: any); | ||
private getFileURLWhenReady; | ||
run(callDetailRecord: any, options?: RecordOptions): { | ||
@@ -12,0 +14,0 @@ keyPressed: any; |
@@ -18,19 +18,35 @@ "use strict"; | ||
class Record extends verb_1.default { | ||
constructor(channel) { | ||
super(channel); | ||
constructor(channel, config) { | ||
super(channel, config); | ||
} | ||
getFileURLWhenReady(name, bucket) { | ||
const sleep = require('sync').sleep; | ||
let cnt = 40; // 40 * 100 is 4 seconds | ||
while (true) { | ||
try { | ||
const result = this.config.storage.getObjectURLSync({ name, bucket }); | ||
return result; | ||
} | ||
catch (e) { | ||
if (cnt <= 0) | ||
return; | ||
sleep(100); | ||
cnt--; | ||
} | ||
} | ||
} | ||
run(callDetailRecord, options = {}) { | ||
let { beep = true, maxDuration = 3600, finishOnKey = '1234567890#*', offset = 0 } = options; | ||
let { beep = true, maxDuration = 3600, finishOnKey = '1234567890#*', offset = 0, format = 'wav' } = options; | ||
validateMaxDuration(maxDuration); | ||
validateBeep(beep); | ||
const format = 'wav'; | ||
const filename = objectid(); | ||
const res = this.channel.recordFile(`/tmp/${filename}`, 'wav', finishOnKey, maxDuration * 1000, offset, beep); | ||
const res = this.channel.recordFile(`/tmp/${filename}`, format, finishOnKey, maxDuration * 1000, offset, beep); | ||
if (res.code !== 200) | ||
throw new Error(res.rawReply); | ||
const recordingUri = this.getFileURLWhenReady(`${filename}.${format}`, this.config.bucket); | ||
return { | ||
keyPressed: res.attributes.result, | ||
recordingUri: `/tmp/${filename}.${format}`, | ||
filename: filename, | ||
format: format, | ||
recordingUri, | ||
filename, | ||
format, | ||
callRef: callDetailRecord.ref | ||
@@ -37,0 +53,0 @@ }; |
@@ -189,3 +189,3 @@ "use strict"; | ||
record(options) { | ||
return new record_1.default(this.channel).run(this.callDetailRecord, options); | ||
return new record_1.default(this.channel, this._config).run(this.callDetailRecord, options); | ||
} | ||
@@ -192,0 +192,0 @@ /** |
{ | ||
"name": "@fonos/voice", | ||
"version": "0.0.23", | ||
"version": "0.0.24", | ||
"description": "Voice verbs", | ||
@@ -37,7 +37,7 @@ "author": "Pedro Sanders <sanderspedro@gmail.com>", | ||
"dependencies": { | ||
"@fonos/logger": "^0.0.23", | ||
"@fonos/tts": "^0.0.23", | ||
"@fonos/logger": "^0.0.24", | ||
"@fonos/tts": "^0.0.24", | ||
"objectid": "^3.2.1" | ||
}, | ||
"gitHead": "14ae147e4f58684df7081a2058a0350c34c48706" | ||
"gitHead": "8fb40d4a7294856db4974d0549de61c48db4b147" | ||
} |
25559
679
+ Added@fonos/logger@0.0.24(transitive)
+ Added@fonos/tts@0.0.24(transitive)
- Removed@fonos/logger@0.0.23(transitive)
- Removed@fonos/tts@0.0.23(transitive)
Updated@fonos/logger@^0.0.24
Updated@fonos/tts@^0.0.24