mirror of
https://github.com/YuzuZensai/NekoMelody.git
synced 2026-01-30 12:32:55 +00:00
✨ feat: Rework on streaming to use WebM format
This commit is contained in:
@@ -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);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user