Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

await toPCM is never completing #9

Open
ghost opened this issue May 25, 2023 · 0 comments
Open

await toPCM is never completing #9

ghost opened this issue May 25, 2023 · 0 comments

Comments

@ghost
Copy link

ghost commented May 25, 2023

I am working with VoskJS & node-record-lpcm16 to do real time voice decoding
Here is my code

const voskJs = require("./voskjs/");
const record = require('node-record-lpcm16');
const wav = require('node-wav');
const fs = require('fs');

const model = voskJs.loadModel("./vosk-model-small-fr-0.22/")
console.log("Model Loaded.");

const recorder = record.record({
  sampleRate: 16000,
  channels: 1,
  threshold: 0.5,
  endOnSilence: true,
  silence: 9999999,
  audioType: "wav"
});

// var artificialData = fs.readFileSync("./mp3-output-ttsfree(dot)com (1).wav");

recorder.stream().on('data', async data => 
{
	console.log(`Data in ${data.length}`);
	var pcmBuffer = await voskJs.toPCM(data);
	console.log(`PCM translated in ${pcmBuffer.length}`);

	const transcriptEvents = await voskJs.transcriptFromBuffer(
		pcmBuffer, 
		model,
		{
			multiThreads: false,
			sampleRate: 16000, 
			grammar: null, 
			alternatives: 0, 
			words: true 
		}
	) 
	console.log(transcriptEvents)

	transcriptEvents.on('partial', res => { // New Word
		console.log(res) 
	});

	transcriptEvents.on('endOfSpeech', res => { // Sentence Detected (silence)
		console.log(res) 
	});

	transcriptEvents.on('final', res => { // Last Sentence
		console.log(res) 
	});

})

/* We need the model all day, we do not clear it
	voskJs.freeModel(model)
*/

This is the console Output:

LOG (VoskAPI:ReadDataFiles():model.cc:282) Loading HCL and G from ./vosk-model-small-fr-0.22//graph/HCLr.fst ./vosk-model-small-fr-0.22//graph/Gr.fst
LOG (VoskAPI:ReadDataFiles():model.cc:303) Loading winfo ./vosk-model-small-fr-0.22//graph/phones/word_boundary.int
Model Loaded.
Data in 8192
Data in 8192
Data in 8192
Data in 8192
Data in 8192
Data in 8192
Data in 8192

Seems like the toPCM is never finishing its promise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants