manual remove audioInput after write
This commit is contained in:
parent
35d603d303
commit
4517752ed8
2 changed files with 13 additions and 7 deletions
|
|
@ -40,7 +40,7 @@ async function transcribeSpeech (audio) {
|
|||
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: {
|
||||
|
|
@ -74,7 +74,7 @@ async function processAudio() {
|
|||
const buf = Buffer.concat(audioInput);
|
||||
play(audioInput);
|
||||
|
||||
while(audioInput.length) { audioInput.pop() };
|
||||
while(audioInput.length) { audioInput.pop() }
|
||||
|
||||
transcribeSpeech({
|
||||
content: buf
|
||||
|
|
@ -117,7 +117,7 @@ async function processAudio() {
|
|||
|
||||
// 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));
|
||||
|
|
@ -140,5 +140,10 @@ setTimeout(async () => {
|
|||
}, 8000);
|
||||
|
||||
setTimeout(() => {
|
||||
ia.resume();
|
||||
}, 10000)
|
||||
|
||||
setTimeout(async () => {
|
||||
ia.pause();
|
||||
}, 9000)
|
||||
processAudio();
|
||||
}, 15000);
|
||||
|
|
|
|||
Loading…
Reference in a new issue