A Chat with GPT: Poem Recorder

Attachments/A Chat with GPT - Poem Recorder 1.png
A Chat with GPT - Poem Recorder 2.png
A Chat with GPT - Poem Recorder 3.png
A Chat with GPT - Poem Recorder 4.png
A Chat with GPT - Poem Recorder 5.png
A Chat with GPT - Poem Recorder 6.png
A Chat with GPT - Poem Recorder 7.png

bramadams.dev is a reader-supported published Zettelkasten. Both free and paid subscriptions are available. If you want to support my work, the best way is by taking out a paid subscription.

A Chat with GPT - Poem Recorder 8.png
A Chat with GPT - Poem Recorder 9.png
A Chat with GPT - Poem Recorder 10.png
A Chat with GPT - Poem Recorder 11.png

poem_recorder.js

const mic = require('mic');
const fs = require('fs');

const micInstance = mic({
    rate: '16000',
    channels: '1',
    debug: true,
});

const micInputStream = micInstance.getAudioStream();
const outputFileStream = fs.WriteStream('output.raw');

micInputStream.pipe(outputFileStream);

console.log('Recording started. Press Ctrl+C to stop.');

micInstance.start();

// Excerpt from Homer's "The Iliad"
const transcript = [
    'Sing, O goddess, the anger of Achilles son of Peleus,',
    'that brought countless ills upon the Achaeans.',
    'Many a brave soul did it send hurrying down to Hades,',
    'and many a hero did it yield a prey to dogs and vultures,',
    'for so were the counsels of Jove fulfilled from the day on',
    'which the son of Atreus, king of men, and great Achilles,',
    'first fell out with one another.'
];

let currentLine = 0;
const interval = setInterval(() => {
    if (currentLine < transcript.length) {
        console.log(transcript[currentLine]);
        currentLine++;
    } else {
        clearInterval(interval);
    }
}, 5000); // Scroll every 5 seconds

// micInputStream.on('data', function(data) {
//     console.log("Recieved Input Stream: " + data.length);
// });
 
micInputStream.on('error', function(err) {
    cosole.log("Error in Input Stream: " + err);
});
 
micInputStream.on('startComplete', function() {
    console.log("Got SIGNAL startComplete");
    setTimeout(function() {
            micInstance.pause();
    }, 5000);
});
    
micInputStream.on('stopComplete', function() {
    console.log("Got SIGNAL stopComplete");
});
    
micInputStream.on('pauseComplete', function() {
    console.log("Got SIGNAL pauseComplete");
    setTimeout(function() {
        micInstance.resume();
    }, 5000);
});
 
micInputStream.on('resumeComplete', function() {
    console.log("Got SIGNAL resumeComplete");
    setTimeout(function() {
        micInstance.stop();
    }, 5000);
});
 
micInputStream.on('silence', function() {
    console.log("Got SIGNAL silence");
});
 
micInputStream.on('processExitComplete', function() {
    console.log("Got SIGNAL processExitComplete");
});

process.on('SIGINT', () => {
    micInstance.stop();
    clearInterval(interval);
    console.log('Recording stopped.');
    process.exit(0);
});


// to play the audio file, run the following command (macOS):
// $ play -b 16 -e signed -c 1 -r 16000 output.raw

It works!

A Chat with GPT - Poem Recorder result.png