let ai: typeof portAudio.AudioIO;
let ao: typeof portAudio.AudioIO;
-let audioInput: Buffer[] = [];
+const audioInput: Buffer[] = [];
const encoding = "base64";
const audioOptions = {
channelCount: 1,
// stop mic data flow on space bar key up.
ai.pause();
const audio = Buffer.concat(audioInput);
- sendAudio(audio);
+ play(audioInput);
+ // sendAudio(audio);
while (audioInput.length) { audioInput.pop(); }
}
}
// utility function used by play func
function bufSplit(input: Array<Buffer>): Array<Buffer> {
- let result: Buffer[] = [];
+ const result: Buffer[] = [];
input.forEach((b: Buffer) => {
// split buffer into two.
result.push(b.slice(0, b.length / 2), b.slice(b.length / 2, b.length));
console.log(`Transcription: ${transcription}`);
}
-let audioInput = [];
+const audioInput = [];
// Create an instance of AudioIO with inOptions (defaults are as below), which will return a ReadableStream
const ia = new portAudio.AudioIO({
inOptions: {
const buf = Buffer.concat(audioInput);
play(audioInput);
- while(audioInput.length) { audioInput.pop() };
+ while(audioInput.length) { audioInput.pop() }
transcribeSpeech({
content: buf
// utility function used by play func
function bufSplit(input){
- let result = [];
+ const result = [];
input.forEach((b) => {
// split buffer into two.
result.push(b.slice(0, b.length / 2), b.slice(b.length / 2, b.length));
}, 8000);
setTimeout(() => {
+ ia.resume();
+}, 10000)
+
+setTimeout(async () => {
ia.pause();
-}, 9000)
+ processAudio();
+}, 15000);