Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mason-at-pieces authored Jun 23, 2024
2 parents c7700e5 + 32336bd commit 1aa346e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,25 @@ async function transcribeAndRespond(filePath) {

console.log(`BOT:\n${answer}`);

// Summarize the response
const summarizer = await pipeline('summarization');
const summary = await summarizer(answer, { max_length: 50, min_length: 25, do_sample: false });

const summarizedText = summary[0].summary_text;
console.log(`Summarized BOT:\n${summarizedText}`);

const synthesizer = await pipeline('text-to-speech', 'Xenova/speecht5_tts', { quantized: false });
const speaker_embeddings = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/speaker_embeddings.bin';
const out = await synthesizer(answer, { speaker_embeddings });
const out = await synthesizer(summarizedText, { speaker_embeddings });

const responseFilePath = 'recordings/response.wav';
wav.fromScratch(1, out.sampling_rate, '32f', out.audio);
fs.writeFileSync(responseFilePath, wav.toBuffer());

// // Play the speech file
// Play the speech file
player.play(responseFilePath, function(err){
if (err) throw err
})
if (err) throw err;
});
})();
} catch (error) {
console.error("Error during transcription or processing:", error);
Expand Down

0 comments on commit 1aa346e

Please sign in to comment.