mirror of
https://github.com/YuzuZensai/NekoMelody.git
synced 2026-01-06 04:33:21 +00:00
31 lines
854 B
TypeScript
31 lines
854 B
TypeScript
import NekoMelody from "../src";
|
|
|
|
import Speaker from "speaker";
|
|
import ffmpeg from "fluent-ffmpeg";
|
|
|
|
const main = async () => {
|
|
// Create the Speaker instance
|
|
const speaker = new Speaker();
|
|
|
|
const videoId = "9PuudPiyma4";
|
|
|
|
// Get the stream from the URL
|
|
const stream = await NekoMelody.stream(
|
|
`https://www.youtube.com/watch?v=${videoId}`,
|
|
);
|
|
|
|
// 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);
|
|
})
|
|
.pipe(speaker, { end: true });
|
|
};
|
|
|
|
main();
|