polyfire-js
Advanced tools
Comparing version 0.2.12 to 0.2.13
@@ -206,3 +206,7 @@ "use strict"; | ||
_this.on("infos", function (data) { | ||
resolve(data); | ||
resolve({ | ||
result: data.result, | ||
tokenUsage: data.token_usage, | ||
ressources: data.ressources, | ||
}); | ||
}); | ||
@@ -209,0 +213,0 @@ })]; |
{ | ||
"name": "polyfire-js", | ||
"version": "0.2.12", | ||
"version": "0.2.13", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "types": "index.d.ts", |
@@ -6,2 +6,3 @@ /// <reference types="node" /> | ||
audioCtx: AudioContext | null; | ||
source: AudioBufferSourceNode | null; | ||
constructor(data: Buffer); | ||
@@ -11,2 +12,5 @@ getMp3Buffer(): Buffer; | ||
play(): Promise<void>; | ||
stop(): Promise<void>; | ||
pause(): Promise<void>; | ||
resume(): Promise<void>; | ||
} | ||
@@ -13,0 +17,0 @@ export declare function tts(text: string, { voice }?: { |
56
tts.js
@@ -69,2 +69,3 @@ "use strict"; | ||
this.data = data; | ||
this.source = null; | ||
this.data = data; | ||
@@ -102,7 +103,7 @@ this.audioCtx = window ? new AudioContext() : null; | ||
if (_this.audioCtx) { | ||
var source = _this.audioCtx.createBufferSource(); | ||
source.buffer = buffer; | ||
source.connect(_this.audioCtx.destination); | ||
source.start(); | ||
source.onended = function () { | ||
_this.source = _this.audioCtx.createBufferSource(); | ||
_this.source.buffer = buffer; | ||
_this.source.connect(_this.audioCtx.destination); | ||
_this.source.start(); | ||
_this.source.onended = function () { | ||
resolve(); | ||
@@ -119,2 +120,47 @@ }; | ||
}; | ||
AudioTTS.prototype.stop = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
if (_this.audioCtx && _this.source) { | ||
_this.source.stop(); | ||
_this.source.onended = function () { | ||
resolve(); | ||
}; | ||
_this.source = null; | ||
} | ||
else { | ||
reject(Error("AudioSource is not playing")); | ||
} | ||
})]; | ||
}); | ||
}); | ||
}; | ||
AudioTTS.prototype.pause = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
if (this.audioCtx && this.source) { | ||
return [2 /*return*/, this.audioCtx.suspend()]; | ||
} | ||
else { | ||
throw Error("AudioSource is not playing"); | ||
} | ||
return [2 /*return*/]; | ||
}); | ||
}); | ||
}; | ||
AudioTTS.prototype.resume = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
if (this.audioCtx && this.source) { | ||
return [2 /*return*/, this.audioCtx.resume()]; | ||
} | ||
else { | ||
throw Error("AudioSource does not exist"); | ||
} | ||
return [2 /*return*/]; | ||
}); | ||
}); | ||
}; | ||
return AudioTTS; | ||
@@ -121,0 +167,0 @@ }()); |
Sorry, the diff of this file is not supported yet
2478633
4117