2024-06-19 11:55:55 +07:00
|
|
|
import NekoMelody from "../src";
|
|
|
|
|
|
|
|
|
|
import Speaker from "speaker";
|
|
|
|
|
import ffmpeg from "fluent-ffmpeg";
|
2024-06-21 00:30:21 +07:00
|
|
|
import { YtDlpProvider } from "../src/providers";
|
2024-06-19 11:55:55 +07:00
|
|
|
|
|
|
|
|
const main = async () => {
|
|
|
|
|
// Create the Speaker instance
|
|
|
|
|
const speaker = new Speaker();
|
|
|
|
|
|
2024-06-19 22:23:05 +07:00
|
|
|
const videoId = "9PuudPiyma4";
|
|
|
|
|
|
2024-06-21 00:30:21 +07:00
|
|
|
// Providers
|
|
|
|
|
const providers = [new YtDlpProvider()];
|
|
|
|
|
const player = NekoMelody.createPlayer(providers);
|
|
|
|
|
|
|
|
|
|
await player.play(`https://www.youtube.com/watch?v=${videoId}`);
|
|
|
|
|
|
|
|
|
|
if (!player.stream) {
|
|
|
|
|
console.error("No input stream");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-06-19 11:55:55 +07:00
|
|
|
|
|
|
|
|
// PCM data from stdin gets piped into the speaker
|
|
|
|
|
const ffmpegProcess = ffmpeg()
|
2024-06-21 00:30:21 +07:00
|
|
|
.input(player.stream)
|
2024-06-19 11:55:55 +07:00
|
|
|
.format("s16le") // Output format (PCM 16-bit little-endian)
|
2024-06-21 00:30:21 +07:00
|
|
|
.audioChannels(2)
|
|
|
|
|
.audioFrequency(44100)
|
2024-06-19 11:55:55 +07:00
|
|
|
.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();
|