2024-06-19 11:55:55 +07:00
|
|
|
import NekoMelody from "../src";
|
|
|
|
|
|
|
|
|
|
import Speaker from "speaker";
|
|
|
|
|
import ffmpeg from "fluent-ffmpeg";
|
|
|
|
|
|
|
|
|
|
const main = async () => {
|
|
|
|
|
// Create the Speaker instance
|
|
|
|
|
const speaker = new Speaker();
|
|
|
|
|
|
2024-06-19 22:23:05 +07:00
|
|
|
const videoId = "9PuudPiyma4";
|
|
|
|
|
|
2024-06-19 11:55:55 +07:00
|
|
|
// Get the stream from the URL
|
|
|
|
|
const stream = await NekoMelody.stream(
|
2024-06-19 22:23:05 +07:00
|
|
|
`https://www.youtube.com/watch?v=${videoId}`,
|
2024-06-19 11:55:55 +07:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// PCM data from stdin gets piped into the speaker
|
|
|
|
|
let audioStream = stream;
|
|
|
|
|
const ffmpegProcess = ffmpeg()
|
|
|
|
|
.input(audioStream)
|
|
|
|
|
.format("s16le") // Output format (PCM 16-bit little-endian)
|
|
|
|
|
//.audioChannels(2) // Number of audio channels
|
|
|
|
|
//.audioFrequency(44100) // Sample rate
|
|
|
|
|
.on("error", (err) => {
|
|
|
|
|
console.error("An error occurred:", err.message);
|
|
|
|
|
})
|
2024-06-19 22:23:05 +07:00
|
|
|
.pipe(speaker, { end: true });
|
2024-06-19 11:55:55 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
main();
|