start AWS provider code cleanup

This commit is contained in:
Dovi Cowan 2023-08-03 19:29:29 +01:00
parent 49d0c65288
commit df2340e0ee
Signed by: dcowan
GPG key ID: 697AE484978D5F89

View file

@ -261,137 +261,6 @@ class GoogleProvider extends Writable {
return; return;
} }
this.cork(); // Buffer any incoming data
this.recognizeStream.end();
this.recognizeStream = null;
}
/**
* Restarts the recognition stream.
*
* @param {Object} [config] - configuration to use
* @param {Object} [config.codec] - the codec to map to an encoding
* @param {string} [config.language] - the language to use
*/
restart(config) {
this.stop();
this.start(config);
}
};
// class AWSProvider extends Writable {
// constructor(options) {
// super();
// this.LanguageCode = "en-GB";
// this.MediaEncoding = "pcm";
// this.credentials = {
// accessKeyId: process.env.AWS_ACCESS_KEY_ID,
// secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
// }
// this.results = [];
// this.stream = new TransformStream();
// this.recognizeStream = this.stream.writable.getWriter();
// (async () => {
// this.readStream = this.stream.readable;
// this.config = {
// LanguageCode: this.LanguageCode,
// MediaEncoding: this.MediaEncoding,
// MediaSampleRateHertz: "8000",
// AudioStream: (async function* () {
// for await (const chunk of this.stream.readable.read()) {
// yield {AudioEvent: {AudioChunk: chunk}};
// }
// // for (let result = await this.readStream.read(); !result.done; result = await this.readStream.read()) {
// // return {AudioEvent: {AudioChunk: result}};
// // }
// })(),
// // AudioStream: this.readStream.read(),
// }
// })
// this.command = null;
// }
// _construct(callback) {
// this.client = new TranscribeStreamingClient({
// region: "eu-west-2",
// credentials: this.credentials
// });
// callback();
// }
// _write(chunk, encoding, callback) {
// if (this.recognizeStream) {
// console.debug("writing chunk");
// this.recognizeStream.write(chunk);
// }
// callback();
// }
// setConfig(config) {
// if (!config) {
// return;
// }
// }
// start(config) {
// if (this.command) {
// return;
// }
// this.setConfig(config);
// config = this.config;
// // this.config.AudioStream = this.recognizeStream;
// this.command = new StartStreamTranscriptionCommand(this.config)
// console.debug("command created")
// this.client.send(this.command).then((response) => {
// print("response from command");
// console.debug(response)
// }).catch((err) => {
// console.log("error in command");
// console.debug(err);
// })
// // (async function() {
// // // console.debug("start async")
// // this.results = await this.client.send(this.command);
// // // .then(async (response) => {
// // // console.debug(JSON.stringify(response));
// // // }).catch(err => {
// // // console.debug("error");
// // // console.debug(err);
// // // });
// // try {
// // // console.debug("event");
// // for await (const event of this.results.TranscriptResultStream) {
// // console.log(JSON.stringify(event));
// // }
// // } catch (err) {
// // console.log("error")
// // console.log(err)
// // }
// // })();
// // console.debug("AWSProvider");
// }
// restart(config) {
// this.start(config);
// }
// }
class AWSProvider extends Writable { class AWSProvider extends Writable {
constructor(options) { constructor(options) {
super(); super();
@ -481,12 +350,6 @@ class AWSProvider extends Writable {
} }
} }
// audioStream().next().then(res => console.debug(res.value.AudioEvent.AudioChunk));
// console.debug('AUDIO');
// this.audioStream().next().then(res => console.debug(res));
// this.audioStream().next().then(res => console.debug(res));
this.param = { this.param = {
LanguageCode: this.LanguageCode, LanguageCode: this.LanguageCode,
MediaEncoding: this.MediaEncoding, MediaEncoding: this.MediaEncoding,
@ -512,19 +375,12 @@ class AWSProvider extends Writable {
} }
// Print all the possible transcripts // Print all the possible transcripts
//
// });
} }
}; };
}).catch((err) => { }).catch((err) => {
console.debug(err); console.debug(err);
}) })
return; return;
(async () => {
console.log("STARTED");
})
} }
stop() { stop() {
@ -546,7 +402,6 @@ class AWSProvider extends Writable {
fs.writeFileSync('stream.wav', wav.toBuffer()); fs.writeFileSync('stream.wav', wav.toBuffer());
// this.recognizeStream.close(); // this.recognizeStream.close();
// console.log(this.recognizeStream);
console.log("End of stream"); console.log("End of stream");