Files
NekoMelody/example/test.ts

31 lines
854 B
TypeScript
Raw Normal View History

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();
const videoId = "9PuudPiyma4";
2024-06-19 11:55:55 +07:00
// Get the stream from the URL
const stream = await NekoMelody.stream(
`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);
})
.pipe(speaker, { end: true });
2024-06-19 11:55:55 +07:00
};
main();