feat: Rework on streaming to use WebM format

This commit is contained in:
2024-06-21 00:30:21 +07:00
parent 237a041301
commit a8062b5fe2
14 changed files with 1553 additions and 400 deletions

View File

@@ -2,6 +2,7 @@ import NekoMelody from "../src";
import Speaker from "speaker";
import ffmpeg from "fluent-ffmpeg";
import { YtDlpProvider } from "../src/providers";
const main = async () => {
// Create the Speaker instance
@@ -9,18 +10,23 @@ const main = async () => {
const videoId = "9PuudPiyma4";
// Get the stream from the URL
const stream = await NekoMelody.stream(
`https://www.youtube.com/watch?v=${videoId}`,
);
// 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;
}
// PCM data from stdin gets piped into the speaker
let audioStream = stream;
const ffmpegProcess = ffmpeg()
.input(audioStream)
.input(player.stream)
.format("s16le") // Output format (PCM 16-bit little-endian)
//.audioChannels(2) // Number of audio channels
//.audioFrequency(44100) // Sample rate
.audioChannels(2)
.audioFrequency(44100)
.on("error", (err) => {
console.error("An error occurred:", err.message);
})