mirror of
https://github.com/YuzuZensai/NekoMelody.git
synced 2026-01-06 04:33:21 +00:00
✨ feat: Simple play-dl stream
This commit is contained in:
31
example/test.ts
Normal file
31
example/test.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import NekoMelody from "../src";
|
||||
|
||||
import Speaker from "speaker";
|
||||
import ffmpeg from "fluent-ffmpeg";
|
||||
|
||||
const main = async () => {
|
||||
// Create the Speaker instance
|
||||
const speaker = new Speaker();
|
||||
|
||||
// Get the stream from the URL
|
||||
const stream = await NekoMelody.stream(
|
||||
"https://www.youtube.com/watch?v=9PuudPiyma4",
|
||||
);
|
||||
|
||||
// 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 })
|
||||
.on("end", () => {
|
||||
console.log("Audio playback finished.");
|
||||
});
|
||||
};
|
||||
|
||||
main();
|
||||
5
src/index.ts
Normal file
5
src/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { stream } from "./stream";
|
||||
|
||||
export default {
|
||||
stream,
|
||||
};
|
||||
7
src/stream.ts
Normal file
7
src/stream.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { Readable } from "stream";
|
||||
import playdl from "play-dl/play-dl";
|
||||
|
||||
export const stream = async (url: string): Promise<Readable> => {
|
||||
let playdlStream = await playdl.stream(url);
|
||||
return playdlStream.stream;
|
||||
};
|
||||
Reference in New Issue
Block a user