@discordjs/voice 0.5.6 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -21
- package/README.md +41 -18
- package/dist/index.d.ts +356 -215
- package/dist/index.js +10 -26
- package/dist/index.js.map +7 -1
- package/dist/index.mjs +10 -0
- package/dist/index.mjs.map +7 -0
- package/package.json +67 -93
- package/dist/DataStore.js +0 -151
- package/dist/DataStore.js.map +0 -1
- package/dist/VoiceConnection.js +0 -494
- package/dist/VoiceConnection.js.map +0 -1
- package/dist/audio/AudioPlayer.js +0 -449
- package/dist/audio/AudioPlayer.js.map +0 -1
- package/dist/audio/AudioPlayerError.js +0 -17
- package/dist/audio/AudioPlayerError.js.map +0 -1
- package/dist/audio/AudioResource.js +0 -164
- package/dist/audio/AudioResource.js.map +0 -1
- package/dist/audio/PlayerSubscription.js +0 -23
- package/dist/audio/PlayerSubscription.js.map +0 -1
- package/dist/audio/TransformerGraph.js +0 -233
- package/dist/audio/TransformerGraph.js.map +0 -1
- package/dist/audio/index.js +0 -18
- package/dist/audio/index.js.map +0 -1
- package/dist/joinVoiceChannel.js +0 -24
- package/dist/joinVoiceChannel.js.map +0 -1
- package/dist/networking/Networking.js +0 -457
- package/dist/networking/Networking.js.map +0 -1
- package/dist/networking/VoiceUDPSocket.js +0 -145
- package/dist/networking/VoiceUDPSocket.js.map +0 -1
- package/dist/networking/VoiceWebSocket.js +0 -129
- package/dist/networking/VoiceWebSocket.js.map +0 -1
- package/dist/networking/index.js +0 -16
- package/dist/networking/index.js.map +0 -1
- package/dist/receive/AudioReceiveStream.js +0 -20
- package/dist/receive/AudioReceiveStream.js.map +0 -1
- package/dist/receive/SSRCMap.js +0 -67
- package/dist/receive/SSRCMap.js.map +0 -1
- package/dist/receive/VoiceReceiver.js +0 -215
- package/dist/receive/VoiceReceiver.js.map +0 -1
- package/dist/receive/index.js +0 -16
- package/dist/receive/index.js.map +0 -1
- package/dist/util/Secretbox.js +0 -50
- package/dist/util/Secretbox.js.map +0 -1
- package/dist/util/adapter.js +0 -3
- package/dist/util/adapter.js.map +0 -1
- package/dist/util/demuxProbe.js +0 -90
- package/dist/util/demuxProbe.js.map +0 -1
- package/dist/util/entersState.js +0 -30
- package/dist/util/entersState.js.map +0 -1
- package/dist/util/generateDependencyReport.js +0 -82
- package/dist/util/generateDependencyReport.js.map +0 -1
- package/dist/util/index.js +0 -17
- package/dist/util/index.js.map +0 -1
- package/dist/util/util.js +0 -7
- package/dist/util/util.js.map +0 -1
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createAudioResource = exports.inferStreamType = exports.NO_CONSTRAINT = exports.VOLUME_CONSTRAINT = exports.AudioResource = void 0;
|
|
4
|
-
const TransformerGraph_1 = require("./TransformerGraph");
|
|
5
|
-
const stream_1 = require("stream");
|
|
6
|
-
const util_1 = require("../util/util");
|
|
7
|
-
const prism_media_1 = require("prism-media");
|
|
8
|
-
const AudioPlayer_1 = require("./AudioPlayer");
|
|
9
|
-
/**
|
|
10
|
-
* Represents an audio resource that can be played by an audio player.
|
|
11
|
-
*
|
|
12
|
-
* @template T - the type for the metadata (if any) of the audio resource.
|
|
13
|
-
*/
|
|
14
|
-
class AudioResource {
|
|
15
|
-
constructor(edges, streams, metadata, silencePaddingFrames) {
|
|
16
|
-
/**
|
|
17
|
-
* The playback duration of this audio resource, given in milliseconds.
|
|
18
|
-
*/
|
|
19
|
-
this.playbackDuration = 0;
|
|
20
|
-
/**
|
|
21
|
-
* Whether or not the stream for this resource has started (data has become readable)
|
|
22
|
-
*/
|
|
23
|
-
this.started = false;
|
|
24
|
-
/**
|
|
25
|
-
* The number of remaining silence frames to play. If -1, the frames have not yet started playing.
|
|
26
|
-
*/
|
|
27
|
-
this.silenceRemaining = -1;
|
|
28
|
-
this.edges = edges;
|
|
29
|
-
this.playStream = streams.length > 1 ? stream_1.pipeline(streams, util_1.noop) : streams[0];
|
|
30
|
-
this.metadata = metadata;
|
|
31
|
-
this.silencePaddingFrames = silencePaddingFrames;
|
|
32
|
-
for (const stream of streams) {
|
|
33
|
-
if (stream instanceof prism_media_1.VolumeTransformer) {
|
|
34
|
-
this.volume = stream;
|
|
35
|
-
}
|
|
36
|
-
else if (stream instanceof prism_media_1.opus.Encoder) {
|
|
37
|
-
this.encoder = stream;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
stream_1.once(this.playStream, 'readable')
|
|
41
|
-
.then(() => (this.started = true))
|
|
42
|
-
.catch(util_1.noop);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Whether this resource is readable. If the underlying resource is no longer readable, this will still return true
|
|
46
|
-
* while there are silence padding frames left to play.
|
|
47
|
-
*/
|
|
48
|
-
get readable() {
|
|
49
|
-
if (this.silenceRemaining === 0)
|
|
50
|
-
return false;
|
|
51
|
-
const real = this.playStream.readable;
|
|
52
|
-
if (!real) {
|
|
53
|
-
if (this.silenceRemaining === -1)
|
|
54
|
-
this.silenceRemaining = this.silencePaddingFrames;
|
|
55
|
-
return this.silenceRemaining !== 0;
|
|
56
|
-
}
|
|
57
|
-
return real;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Whether this resource has ended or not.
|
|
61
|
-
*/
|
|
62
|
-
get ended() {
|
|
63
|
-
return this.playStream.readableEnded || this.playStream.destroyed || this.silenceRemaining === 0;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Attempts to read an Opus packet from the audio resource. If a packet is available, the playbackDuration
|
|
67
|
-
* is incremented.
|
|
68
|
-
* @internal
|
|
69
|
-
* @remarks
|
|
70
|
-
* It is advisable to check that the playStream is readable before calling this method. While no runtime
|
|
71
|
-
* errors will be thrown, you should check that the resource is still available before attempting to
|
|
72
|
-
* read from it.
|
|
73
|
-
*/
|
|
74
|
-
read() {
|
|
75
|
-
if (this.silenceRemaining === 0) {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
else if (this.silenceRemaining > 0) {
|
|
79
|
-
this.silenceRemaining--;
|
|
80
|
-
return AudioPlayer_1.SILENCE_FRAME;
|
|
81
|
-
}
|
|
82
|
-
const packet = this.playStream.read();
|
|
83
|
-
if (packet) {
|
|
84
|
-
this.playbackDuration += 20;
|
|
85
|
-
}
|
|
86
|
-
return packet;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
exports.AudioResource = AudioResource;
|
|
90
|
-
/**
|
|
91
|
-
* Ensures that a path contains at least one volume transforming component
|
|
92
|
-
*
|
|
93
|
-
* @param path - The path to validate constraints on
|
|
94
|
-
*/
|
|
95
|
-
const VOLUME_CONSTRAINT = (path) => path.some((edge) => edge.type === TransformerGraph_1.TransformerType.InlineVolume);
|
|
96
|
-
exports.VOLUME_CONSTRAINT = VOLUME_CONSTRAINT;
|
|
97
|
-
const NO_CONSTRAINT = () => true;
|
|
98
|
-
exports.NO_CONSTRAINT = NO_CONSTRAINT;
|
|
99
|
-
/**
|
|
100
|
-
* Tries to infer the type of a stream to aid with transcoder pipelining.
|
|
101
|
-
*
|
|
102
|
-
* @param stream - The stream to infer the type of
|
|
103
|
-
*/
|
|
104
|
-
function inferStreamType(stream) {
|
|
105
|
-
if (stream instanceof prism_media_1.opus.Encoder) {
|
|
106
|
-
return { streamType: TransformerGraph_1.StreamType.Opus, hasVolume: false };
|
|
107
|
-
}
|
|
108
|
-
else if (stream instanceof prism_media_1.opus.Decoder) {
|
|
109
|
-
return { streamType: TransformerGraph_1.StreamType.Raw, hasVolume: false };
|
|
110
|
-
}
|
|
111
|
-
else if (stream instanceof prism_media_1.VolumeTransformer) {
|
|
112
|
-
return { streamType: TransformerGraph_1.StreamType.Raw, hasVolume: true };
|
|
113
|
-
}
|
|
114
|
-
else if (stream instanceof prism_media_1.opus.OggDemuxer) {
|
|
115
|
-
return { streamType: TransformerGraph_1.StreamType.Opus, hasVolume: false };
|
|
116
|
-
}
|
|
117
|
-
else if (stream instanceof prism_media_1.opus.WebmDemuxer) {
|
|
118
|
-
return { streamType: TransformerGraph_1.StreamType.Opus, hasVolume: false };
|
|
119
|
-
}
|
|
120
|
-
return { streamType: TransformerGraph_1.StreamType.Arbitrary, hasVolume: false };
|
|
121
|
-
}
|
|
122
|
-
exports.inferStreamType = inferStreamType;
|
|
123
|
-
/**
|
|
124
|
-
* Creates an audio resource that can be played be audio players.
|
|
125
|
-
*
|
|
126
|
-
* @remarks
|
|
127
|
-
* If the input is given as a string, then the inputType option will be overridden and FFmpeg will be used.
|
|
128
|
-
*
|
|
129
|
-
* If the input is not in the correct format, then a pipeline of transcoders and transformers will be created
|
|
130
|
-
* to ensure that the resultant stream is in the correct format for playback. This could involve using FFmpeg,
|
|
131
|
-
* Opus transcoders, and Ogg/WebM demuxers.
|
|
132
|
-
*
|
|
133
|
-
* @param input - The resource to play.
|
|
134
|
-
* @param options - Configurable options for creating the resource.
|
|
135
|
-
*
|
|
136
|
-
* @template T - the type for the metadata (if any) of the audio resource.
|
|
137
|
-
*/
|
|
138
|
-
function createAudioResource(input, options = {}) {
|
|
139
|
-
var _a, _b, _c, _d;
|
|
140
|
-
let inputType = options.inputType;
|
|
141
|
-
let needsInlineVolume = Boolean(options.inlineVolume);
|
|
142
|
-
// string inputs can only be used with FFmpeg
|
|
143
|
-
if (typeof input === 'string') {
|
|
144
|
-
inputType = TransformerGraph_1.StreamType.Arbitrary;
|
|
145
|
-
}
|
|
146
|
-
else if (typeof inputType === 'undefined') {
|
|
147
|
-
const analysis = inferStreamType(input);
|
|
148
|
-
inputType = analysis.streamType;
|
|
149
|
-
needsInlineVolume = needsInlineVolume && !analysis.hasVolume;
|
|
150
|
-
}
|
|
151
|
-
const transformerPipeline = TransformerGraph_1.findPipeline(inputType, needsInlineVolume ? exports.VOLUME_CONSTRAINT : exports.NO_CONSTRAINT);
|
|
152
|
-
if (transformerPipeline.length === 0) {
|
|
153
|
-
if (typeof input === 'string')
|
|
154
|
-
throw new Error(`Invalid pipeline constructed for string resource '${input}'`);
|
|
155
|
-
// No adjustments required
|
|
156
|
-
return new AudioResource([], [input], ((_a = options.metadata) !== null && _a !== void 0 ? _a : null), (_b = options.silencePaddingFrames) !== null && _b !== void 0 ? _b : 5);
|
|
157
|
-
}
|
|
158
|
-
const streams = transformerPipeline.map((edge) => edge.transformer(input));
|
|
159
|
-
if (typeof input !== 'string')
|
|
160
|
-
streams.unshift(input);
|
|
161
|
-
return new AudioResource(transformerPipeline, streams, ((_c = options.metadata) !== null && _c !== void 0 ? _c : null), (_d = options.silencePaddingFrames) !== null && _d !== void 0 ? _d : 5);
|
|
162
|
-
}
|
|
163
|
-
exports.createAudioResource = createAudioResource;
|
|
164
|
-
//# sourceMappingURL=AudioResource.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AudioResource.js","sourceRoot":"","sources":["../../src/audio/AudioResource.ts"],"names":[],"mappings":";;;AAAA,yDAAqF;AACrF,mCAAkD;AAClD,uCAAoC;AACpC,6CAAsD;AACtD,+CAA2D;AAiC3D;;;;GAIG;AACH,MAAa,aAAa;IAuDzB,YAAmB,KAAsB,EAAE,OAA4B,EAAE,QAAW,EAAE,oBAA4B;QApBlH;;WAEG;QACI,qBAAgB,GAAG,CAAC,CAAC;QAE5B;;WAEG;QACI,YAAO,GAAG,KAAK,CAAC;QAOvB;;WAEG;QACI,qBAAgB,GAAG,CAAC,CAAC,CAAC;QAG5B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAE,iBAAQ,CAAC,OAAO,EAAE,WAAI,CAAqB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACjG,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;QAEjD,KAAK,MAAM,MAAM,IAAI,OAAO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AC,OAAO,CAAC,KAAK,CAAC,CAAC;IAEtD,OAAO,IAAI,aAAa,CACvB,mBAAmB,EACnB,OAAO,EACP,CAAC,MAAA,OAAO,CAAC,QAAQ,mCAAI,IAAI,CAAM,EAC/B,MAAA,OAAO,CAAC,oBAAoB,mCAAI,CAAC,CACjC,CAAC;AACH,CAAC;AAhCD,kDAgCC","sourcesContent":["import { Edge, findPipeline, StreamType, TransformerType } from './TransformerGraph';\nimport { once, pipeline, Readable } from 'stream';\nimport { noop } from '../util/util';\nimport { VolumeTransformer, opus } from 'prism-media';\nimport { AudioPlayer, SILENCE_FRAME } from './AudioPlayer';\n\n/**\n * Options that are set when creating a new audio resource.\n *\n * @template T - the type for the metadata (if any) of the audio resource.\n */\ninterface CreateAudioResourceOptions<T> {\n\t/**\n\t * The type of the input stream. Defaults to `StreamType.Arbitrary`.\n\t */\n\tinputType?: StreamType;\n\n\t/**\n\t * Optional metadata that can be attached to the resource (e.g. track title, random ID).\n\t * This is useful for identification purposes when the resource is passed around in events.\n\t * See {@link AudioResource.metadata}\n\t */\n\tmetadata?: T;\n\n\t/**\n\t * Whether or not inline volume should be enabled. If enabled, you will be able to change the volume\n\t * of the stream on-the-fly. However, this also increases the performance cost of playback. Defaults to `false`.\n\t */\n\tinlineVolume?: boolean;\n\n\t/**\n\t * The number of silence frames to append to the end of the resource's audio stream, to prevent interpolation glitches.\n\t * Defaults to 5.\n\t */\n\tsilencePaddingFrames?: number;\n}\n\n/**\n * Represents an audio resource that can be played by an audio player.\n *\n * @template T - the type for the metadata (if any) of the audio resource.\n */\nexport class AudioResource<T = unknown> {\n\t/**\n\t * An object-mode Readable stream that emits Opus packets. This is what is played by audio players.\n\t */\n\tpublic readonly playStream: Readable;\n\n\t/**\n\t * The pipeline used to convert the input stream into a playable format. For example, this may\n\t * contain an FFmpeg component for arbitrary inputs, and it may contain a VolumeTransformer component\n\t * for resources with inline volume transformation enabled.\n\t */\n\tpublic readonly edges: readonly Edge[];\n\n\t/**\n\t * Optional metadata that can be used to identify the resource.\n\t */\n\tpublic metadata: T;\n\n\t/**\n\t * If the resource was created with inline volume transformation enabled, then this will be a\n\t * prism-media VolumeTransformer. You can use this to alter the volume of the stream.\n\t */\n\tpublic readonly volume?: VolumeTransformer;\n\n\t/**\n\t * If using an Opus encoder to create this audio resource, then this will be a prism-media opus.Encoder.\n\t * You can use this to control settings such as bitrate, FEC, PLP.\n\t */\n\tpublic readonly encoder?: opus.Encoder;\n\n\t/**\n\t * The audio player that the resource is subscribed to, if any.\n\t */\n\tpublic audioPlayer?: AudioPlayer;\n\n\t/**\n\t * The playback duration of this audio resource, given in milliseconds.\n\t */\n\tpublic playbackDuration = 0;\n\n\t/**\n\t * Whether or not the stream for this resource has started (data has become readable)\n\t */\n\tpublic started = false;\n\n\t/**\n\t * The number of silence frames to append to the end of the resource's audio stream, to prevent interpolation glitches.\n\t */\n\tpublic readonly silencePaddingFrames: number;\n\n\t/**\n\t * The number of remaining silence frames to play. If -1, the frames have not yet started playing.\n\t */\n\tpublic silenceRemaining = -1;\n\n\tpublic constructor(edges: readonly Edge[], streams: readonly Readable[], metadata: T, silencePaddingFrames: number) {\n\t\tthis.edges = edges;\n\t\tthis.playStream = streams.length > 1 ? (pipeline(streams, noop) as any as Readable) : streams[0];\n\t\tthis.metadata = metadata;\n\t\tthis.silencePaddingFrames = silencePaddingFrames;\n\n\t\tfor (const stream of streams) {\n\t\t\tif (stream instanceof VolumeTransformer) {\n\t\t\t\tthis.volume = stream;\n\t\t\t} else if (stream instanceof opus.Encoder) {\n\t\t\t\tthis.encoder = stream;\n\t\t\t}\n\t\t}\n\n\t\tonce(this.playStream, 'readable')\n\t\t\t.then(() => (this.started = true))\n\t\t\t.catch(noop);\n\t}\n\n\t/**\n\t * Whether this resource is readable. If the underlying resource is no longer readable, this will still return true\n\t * while there are silence padding frames left to play.\n\t */\n\tpublic get readable() {\n\t\tif (this.silenceRemaining === 0) return false;\n\t\tconst real = this.playStream.readable;\n\t\tif (!real) {\n\t\t\tif (this.silenceRemaining === -1) this.silenceRemaining = this.silencePaddingFrames;\n\t\t\treturn this.silenceRemaining !== 0;\n\t\t}\n\t\treturn real;\n\t}\n\n\t/**\n\t * Whether this resource has ended or not.\n\t */\n\tpublic get ended() {\n\t\treturn this.playStream.readableEnded || this.playStream.destroyed || this.silenceRemaining === 0;\n\t}\n\n\t/**\n\t * Attempts to read an Opus packet from the audio resource. If a packet is available, the playbackDuration\n\t * is incremented.\n\t * @internal\n\t * @remarks\n\t * It is advisable to check that the playStream is readable before calling this method. While no runtime\n\t * errors will be thrown, you should check that the resource is still available before attempting to\n\t * read from it.\n\t */\n\tpublic read(): Buffer | null {\n\t\tif (this.silenceRemaining === 0) {\n\t\t\treturn null;\n\t\t} else if (this.silenceRemaining > 0) {\n\t\t\tthis.silenceRemaining--;\n\t\t\treturn SILENCE_FRAME;\n\t\t}\n\t\tconst packet: Buffer | null = this.playStream.read();\n\t\tif (packet) {\n\t\t\tthis.playbackDuration += 20;\n\t\t}\n\t\treturn packet;\n\t}\n}\n\n/**\n * Ensures that a path contains at least one volume transforming component\n *\n * @param path - The path to validate constraints on\n */\nexport const VOLUME_CONSTRAINT = (path: Edge[]) => path.some((edge) => edge.type === TransformerType.InlineVolume);\n\nexport const NO_CONSTRAINT = () => true;\n\n/**\n * Tries to infer the type of a stream to aid with transcoder pipelining.\n *\n * @param stream - The stream to infer the type of\n */\nexport function inferStreamType(stream: Readable): {\n\tstreamType: StreamType;\n\thasVolume: boolean;\n} {\n\tif (stream instanceof opus.Encoder) {\n\t\treturn { streamType: StreamType.Opus, hasVolume: false };\n\t} else if (stream instanceof opus.Decoder) {\n\t\treturn { streamType: StreamType.Raw, hasVolume: false };\n\t} else if (stream instanceof VolumeTransformer) {\n\t\treturn { streamType: StreamType.Raw, hasVolume: true };\n\t} else if (stream instanceof opus.OggDemuxer) {\n\t\treturn { streamType: StreamType.Opus, hasVolume: false };\n\t} else if (stream instanceof opus.WebmDemuxer) {\n\t\treturn { streamType: StreamType.Opus, hasVolume: false };\n\t}\n\treturn { streamType: StreamType.Arbitrary, hasVolume: false };\n}\n\nexport function createAudioResource<T>(\n\tinput: string | Readable,\n\toptions: CreateAudioResourceOptions<T> &\n\t\tPick<\n\t\t\tT extends null | undefined ? CreateAudioResourceOptions<T> : Required<CreateAudioResourceOptions<T>>,\n\t\t\t'metadata'\n\t\t>,\n): AudioResource<T extends null | undefined ? null : T>;\n\nexport function createAudioResource<T extends null | undefined>(\n\tinput: string | Readable,\n\toptions?: Omit<CreateAudioResourceOptions<T>, 'metadata'>,\n): AudioResource<null>;\n\n/**\n * Creates an audio resource that can be played be audio players.\n *\n * @remarks\n * If the input is given as a string, then the inputType option will be overridden and FFmpeg will be used.\n *\n * If the input is not in the correct format, then a pipeline of transcoders and transformers will be created\n * to ensure that the resultant stream is in the correct format for playback. This could involve using FFmpeg,\n * Opus transcoders, and Ogg/WebM demuxers.\n *\n * @param input - The resource to play.\n * @param options - Configurable options for creating the resource.\n *\n * @template T - the type for the metadata (if any) of the audio resource.\n */\nexport function createAudioResource<T>(\n\tinput: string | Readable,\n\toptions: CreateAudioResourceOptions<T> = {},\n): AudioResource<T> {\n\tlet inputType = options.inputType;\n\tlet needsInlineVolume = Boolean(options.inlineVolume);\n\n\t// string inputs can only be used with FFmpeg\n\tif (typeof input === 'string') {\n\t\tinputType = StreamType.Arbitrary;\n\t} else if (typeof inputType === 'undefined') {\n\t\tconst analysis = inferStreamType(input);\n\t\tinputType = analysis.streamType;\n\t\tneedsInlineVolume = needsInlineVolume && !analysis.hasVolume;\n\t}\n\n\tconst transformerPipeline = findPipeline(inputType, needsInlineVolume ? VOLUME_CONSTRAINT : NO_CONSTRAINT);\n\n\tif (transformerPipeline.length === 0) {\n\t\tif (typeof input === 'string') throw new Error(`Invalid pipeline constructed for string resource '${input}'`);\n\t\t// No adjustments required\n\t\treturn new AudioResource<T>([], [input], (options.metadata ?? null) as T, options.silencePaddingFrames ?? 5);\n\t}\n\tconst streams = transformerPipeline.map((edge) => edge.transformer(input));\n\tif (typeof input !== 'string') streams.unshift(input);\n\n\treturn new AudioResource<T>(\n\t\ttransformerPipeline,\n\t\tstreams,\n\t\t(options.metadata ?? null) as T,\n\t\toptions.silencePaddingFrames ?? 5,\n\t);\n}\n"]}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PlayerSubscription = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Represents a subscription of a voice connection to an audio player, allowing
|
|
6
|
-
* the audio player to play audio on the voice connection.
|
|
7
|
-
*/
|
|
8
|
-
class PlayerSubscription {
|
|
9
|
-
constructor(connection, player) {
|
|
10
|
-
this.connection = connection;
|
|
11
|
-
this.player = player;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Unsubscribes the connection from the audio player, meaning that the
|
|
15
|
-
* audio player cannot stream audio to it until a new subscription is made.
|
|
16
|
-
*/
|
|
17
|
-
unsubscribe() {
|
|
18
|
-
this.connection['onSubscriptionRemoved'](this);
|
|
19
|
-
this.player['unsubscribe'](this);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.PlayerSubscription = PlayerSubscription;
|
|
23
|
-
//# sourceMappingURL=PlayerSubscription.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PlayerSubscription.js","sourceRoot":"","sources":["../../src/audio/PlayerSubscription.ts"],"names":[],"mappings":";;;AAIA;;;GAGG;AACH,MAAa,kBAAkB;IAW9B,YAAmB,UAA2B,EAAE,MAAmB;QAClE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAED;;;OAGG;IACI,WAAW;QACjB,IAAI,CAAC,UAAU,CAAC,uBAAuB,CAAC,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACD;AAxBD,gDAwBC","sourcesContent":["/* eslint-disable @typescript-eslint/dot-notation */\nimport { VoiceConnection } from '../VoiceConnection';\nimport { AudioPlayer } from './AudioPlayer';\n\n/**\n * Represents a subscription of a voice connection to an audio player, allowing\n * the audio player to play audio on the voice connection.\n */\nexport class PlayerSubscription {\n\t/**\n\t * The voice connection of this subscription\n\t */\n\tpublic readonly connection: VoiceConnection;\n\n\t/**\n\t * The audio player of this subscription\n\t */\n\tpublic readonly player: AudioPlayer;\n\n\tpublic constructor(connection: VoiceConnection, player: AudioPlayer) {\n\t\tthis.connection = connection;\n\t\tthis.player = player;\n\t}\n\n\t/**\n\t * Unsubscribes the connection from the audio player, meaning that the\n\t * audio player cannot stream audio to it until a new subscription is made.\n\t */\n\tpublic unsubscribe() {\n\t\tthis.connection['onSubscriptionRemoved'](this);\n\t\tthis.player['unsubscribe'](this);\n\t}\n}\n"]}
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.findPipeline = exports.getNode = exports.Node = exports.TransformerType = exports.StreamType = void 0;
|
|
23
|
-
const prism = __importStar(require("prism-media"));
|
|
24
|
-
/*
|
|
25
|
-
This module creates a Transformer Graph to figure out what the most efficient way
|
|
26
|
-
of transforming the input stream into something playable would be.
|
|
27
|
-
*/
|
|
28
|
-
const FFMPEG_PCM_ARGUMENTS = ['-analyzeduration', '0', '-loglevel', '0', '-f', 's16le', '-ar', '48000', '-ac', '2'];
|
|
29
|
-
const FFMPEG_OPUS_ARGUMENTS = [
|
|
30
|
-
'-analyzeduration',
|
|
31
|
-
'0',
|
|
32
|
-
'-loglevel',
|
|
33
|
-
'0',
|
|
34
|
-
'-acodec',
|
|
35
|
-
'libopus',
|
|
36
|
-
'-f',
|
|
37
|
-
'opus',
|
|
38
|
-
'-ar',
|
|
39
|
-
'48000',
|
|
40
|
-
'-ac',
|
|
41
|
-
'2',
|
|
42
|
-
];
|
|
43
|
-
/**
|
|
44
|
-
* The different types of stream that can exist within the pipeline
|
|
45
|
-
*
|
|
46
|
-
* @remarks
|
|
47
|
-
* - `Arbitrary` - the type of the stream at this point is unknown.
|
|
48
|
-
*
|
|
49
|
-
* - `Raw` - the stream at this point is s16le PCM.
|
|
50
|
-
*
|
|
51
|
-
* - `OggOpus` - the stream at this point is Opus audio encoded in an Ogg wrapper.
|
|
52
|
-
*
|
|
53
|
-
* - `WebmOpus` - the stream at this point is Opus audio encoded in a WebM wrapper.
|
|
54
|
-
*
|
|
55
|
-
* - `Opus` - the stream at this point is Opus audio, and the stream is in object-mode. This is ready to play.
|
|
56
|
-
*/
|
|
57
|
-
var StreamType;
|
|
58
|
-
(function (StreamType) {
|
|
59
|
-
StreamType["Arbitrary"] = "arbitrary";
|
|
60
|
-
StreamType["Raw"] = "raw";
|
|
61
|
-
StreamType["OggOpus"] = "ogg/opus";
|
|
62
|
-
StreamType["WebmOpus"] = "webm/opus";
|
|
63
|
-
StreamType["Opus"] = "opus";
|
|
64
|
-
})(StreamType = exports.StreamType || (exports.StreamType = {}));
|
|
65
|
-
/**
|
|
66
|
-
* The different types of transformers that can exist within the pipeline
|
|
67
|
-
*/
|
|
68
|
-
var TransformerType;
|
|
69
|
-
(function (TransformerType) {
|
|
70
|
-
TransformerType["FFmpegPCM"] = "ffmpeg pcm";
|
|
71
|
-
TransformerType["FFmpegOgg"] = "ffmpeg ogg";
|
|
72
|
-
TransformerType["OpusEncoder"] = "opus encoder";
|
|
73
|
-
TransformerType["OpusDecoder"] = "opus decoder";
|
|
74
|
-
TransformerType["OggOpusDemuxer"] = "ogg/opus demuxer";
|
|
75
|
-
TransformerType["WebmOpusDemuxer"] = "webm/opus demuxer";
|
|
76
|
-
TransformerType["InlineVolume"] = "volume transformer";
|
|
77
|
-
})(TransformerType = exports.TransformerType || (exports.TransformerType = {}));
|
|
78
|
-
/**
|
|
79
|
-
* Represents a type of stream within the graph, e.g. an Opus stream, or a stream of raw audio.
|
|
80
|
-
*/
|
|
81
|
-
class Node {
|
|
82
|
-
constructor(type) {
|
|
83
|
-
/**
|
|
84
|
-
* The outbound edges from this node
|
|
85
|
-
*/
|
|
86
|
-
this.edges = [];
|
|
87
|
-
this.type = type;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Creates an outbound edge from this node
|
|
91
|
-
*
|
|
92
|
-
* @param edge - The edge to create
|
|
93
|
-
*/
|
|
94
|
-
addEdge(edge) {
|
|
95
|
-
this.edges.push({ ...edge, from: this });
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
exports.Node = Node;
|
|
99
|
-
// Create a node for each stream type
|
|
100
|
-
const NODES = new Map();
|
|
101
|
-
for (const streamType of Object.values(StreamType)) {
|
|
102
|
-
NODES.set(streamType, new Node(streamType));
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Gets a node from its stream type
|
|
106
|
-
*
|
|
107
|
-
* @param type - The stream type of the target node
|
|
108
|
-
*/
|
|
109
|
-
function getNode(type) {
|
|
110
|
-
const node = NODES.get(type);
|
|
111
|
-
if (!node)
|
|
112
|
-
throw new Error(`Node type '${type}' does not exist!`);
|
|
113
|
-
return node;
|
|
114
|
-
}
|
|
115
|
-
exports.getNode = getNode;
|
|
116
|
-
getNode(StreamType.Raw).addEdge({
|
|
117
|
-
type: TransformerType.OpusEncoder,
|
|
118
|
-
to: getNode(StreamType.Opus),
|
|
119
|
-
cost: 1.5,
|
|
120
|
-
transformer: () => new prism.opus.Encoder({ rate: 48000, channels: 2, frameSize: 960 }),
|
|
121
|
-
});
|
|
122
|
-
getNode(StreamType.Opus).addEdge({
|
|
123
|
-
type: TransformerType.OpusDecoder,
|
|
124
|
-
to: getNode(StreamType.Raw),
|
|
125
|
-
cost: 1.5,
|
|
126
|
-
transformer: () => new prism.opus.Decoder({ rate: 48000, channels: 2, frameSize: 960 }),
|
|
127
|
-
});
|
|
128
|
-
getNode(StreamType.OggOpus).addEdge({
|
|
129
|
-
type: TransformerType.OggOpusDemuxer,
|
|
130
|
-
to: getNode(StreamType.Opus),
|
|
131
|
-
cost: 1,
|
|
132
|
-
transformer: () => new prism.opus.OggDemuxer(),
|
|
133
|
-
});
|
|
134
|
-
getNode(StreamType.WebmOpus).addEdge({
|
|
135
|
-
type: TransformerType.WebmOpusDemuxer,
|
|
136
|
-
to: getNode(StreamType.Opus),
|
|
137
|
-
cost: 1,
|
|
138
|
-
transformer: () => new prism.opus.WebmDemuxer(),
|
|
139
|
-
});
|
|
140
|
-
const FFMPEG_PCM_EDGE = {
|
|
141
|
-
type: TransformerType.FFmpegPCM,
|
|
142
|
-
to: getNode(StreamType.Raw),
|
|
143
|
-
cost: 2,
|
|
144
|
-
transformer: (input) => new prism.FFmpeg({
|
|
145
|
-
args: typeof input === 'string' ? ['-i', input, ...FFMPEG_PCM_ARGUMENTS] : FFMPEG_PCM_ARGUMENTS,
|
|
146
|
-
}),
|
|
147
|
-
};
|
|
148
|
-
getNode(StreamType.Arbitrary).addEdge(FFMPEG_PCM_EDGE);
|
|
149
|
-
getNode(StreamType.OggOpus).addEdge(FFMPEG_PCM_EDGE);
|
|
150
|
-
getNode(StreamType.WebmOpus).addEdge(FFMPEG_PCM_EDGE);
|
|
151
|
-
getNode(StreamType.Raw).addEdge({
|
|
152
|
-
type: TransformerType.InlineVolume,
|
|
153
|
-
to: getNode(StreamType.Raw),
|
|
154
|
-
cost: 0.5,
|
|
155
|
-
transformer: () => new prism.VolumeTransformer({ type: 's16le' }),
|
|
156
|
-
});
|
|
157
|
-
// Try to enable FFmpeg Ogg optimizations
|
|
158
|
-
function canEnableFFmpegOptimizations() {
|
|
159
|
-
try {
|
|
160
|
-
return prism.FFmpeg.getInfo().output.includes('--enable-libopus');
|
|
161
|
-
}
|
|
162
|
-
catch { }
|
|
163
|
-
return false;
|
|
164
|
-
}
|
|
165
|
-
if (canEnableFFmpegOptimizations()) {
|
|
166
|
-
const FFMPEG_OGG_EDGE = {
|
|
167
|
-
type: TransformerType.FFmpegOgg,
|
|
168
|
-
to: getNode(StreamType.OggOpus),
|
|
169
|
-
cost: 2,
|
|
170
|
-
transformer: (input) => new prism.FFmpeg({
|
|
171
|
-
args: typeof input === 'string' ? ['-i', input, ...FFMPEG_OPUS_ARGUMENTS] : FFMPEG_OPUS_ARGUMENTS,
|
|
172
|
-
}),
|
|
173
|
-
};
|
|
174
|
-
getNode(StreamType.Arbitrary).addEdge(FFMPEG_OGG_EDGE);
|
|
175
|
-
// Include Ogg and WebM as well in case they have different sampling rates or are mono instead of stereo
|
|
176
|
-
// at the moment, this will not do anything. However, if/when detection for correct Opus headers is
|
|
177
|
-
// implemented, this will help inform the voice engine that it is able to transcode the audio.
|
|
178
|
-
getNode(StreamType.OggOpus).addEdge(FFMPEG_OGG_EDGE);
|
|
179
|
-
getNode(StreamType.WebmOpus).addEdge(FFMPEG_OGG_EDGE);
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Finds the shortest cost path from node A to node B.
|
|
183
|
-
*
|
|
184
|
-
* @param from - The start node
|
|
185
|
-
* @param constraints - Extra validation for a potential solution. Takes a path, returns true if the path is valid.
|
|
186
|
-
* @param goal - The target node
|
|
187
|
-
* @param path - The running path
|
|
188
|
-
* @param depth - The number of remaining recursions
|
|
189
|
-
*/
|
|
190
|
-
function findPath(from, constraints, goal = getNode(StreamType.Opus), path = [], depth = 5) {
|
|
191
|
-
if (from === goal && constraints(path)) {
|
|
192
|
-
return { cost: 0 };
|
|
193
|
-
}
|
|
194
|
-
else if (depth === 0) {
|
|
195
|
-
return { cost: Infinity };
|
|
196
|
-
}
|
|
197
|
-
let currentBest = undefined;
|
|
198
|
-
for (const edge of from.edges) {
|
|
199
|
-
if (currentBest && edge.cost > currentBest.cost)
|
|
200
|
-
continue;
|
|
201
|
-
const next = findPath(edge.to, constraints, goal, [...path, edge], depth - 1);
|
|
202
|
-
const cost = edge.cost + next.cost;
|
|
203
|
-
if (!currentBest || cost < currentBest.cost) {
|
|
204
|
-
currentBest = { cost, edge, next };
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
return currentBest !== null && currentBest !== void 0 ? currentBest : { cost: Infinity };
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Takes the solution from findPath and assembles it into a list of edges
|
|
211
|
-
*
|
|
212
|
-
* @param step - The first step of the path
|
|
213
|
-
*/
|
|
214
|
-
function constructPipeline(step) {
|
|
215
|
-
const edges = [];
|
|
216
|
-
let current = step;
|
|
217
|
-
while (current === null || current === void 0 ? void 0 : current.edge) {
|
|
218
|
-
edges.push(current.edge);
|
|
219
|
-
current = current.next;
|
|
220
|
-
}
|
|
221
|
-
return edges;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Finds the lowest-cost pipeline to convert the input stream type into an Opus stream
|
|
225
|
-
*
|
|
226
|
-
* @param from - The stream type to start from
|
|
227
|
-
* @param constraint - Extra constraints that may be imposed on potential solution
|
|
228
|
-
*/
|
|
229
|
-
function findPipeline(from, constraint) {
|
|
230
|
-
return constructPipeline(findPath(getNode(from), constraint));
|
|
231
|
-
}
|
|
232
|
-
exports.findPipeline = findPipeline;
|
|
233
|
-
//# sourceMappingURL=TransformerGraph.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TransformerGraph.js","sourceRoot":"","sources":["../../src/audio/TransformerGraph.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AACA,mDAAqC;AAErC;;;EAGE;AAEF,MAAM,oBAAoB,GAAG,CAAC,kBAAkB,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;AACpH,MAAM,qBAAqB,GAAG;IAC7B,kBAAkB;IAClB,GAAG;IACH,WAAW;IACX,GAAG;IACH,SAAS;IACT,SAAS;IACT,IAAI;IACJ,MAAM;IACN,KAAK;IACL,OAAO;IACP,KAAK;IACL,GAAG;CACH,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,IAAY,UAMX;AAND,WAAY,UAAU;IACrB,qCAAuB,CAAA;IACvB,yBAAW,CAAA;IACX,kCAAoB,CAAA;IACpB,oCAAsB,CAAA;IACtB,2BAAa,CAAA;AACd,CAAC,EANW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAMrB;AAED;;GAEG;AACH,IAAY,eAQX;AARD,WAAY,eAAe;IAC1B,2CAAwB,CAAA;IACxB,2CAAwB,CAAA;IACxB,+CAA4B,CAAA;IAC5B,+CAA4B,CAAA;IAC5B,sDAAmC,CAAA;IACnC,wDAAqC,CAAA;IACrC,sDAAmC,CAAA;AACpC,CAAC,EARW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAQ1B;AAaD;;GAEG;AACH,MAAa,IAAI;IAWhB,YAAmB,IAAgB;QAV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AAI,OAAO,GAAqB,IAAI,CAAC;IACrC,OAAO,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,EAAE;QACrB,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACzB,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;KACvB;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,IAAgB,EAAE,UAAqC;IACnF,OAAO,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC;AAC/D,CAAC;AAFD,oCAEC","sourcesContent":["import { Readable } from 'stream';\nimport * as prism from 'prism-media';\n\n/*\n\tThis module creates a Transformer Graph to figure out what the most efficient way\n\tof transforming the input stream into something playable would be.\n*/\n\nconst FFMPEG_PCM_ARGUMENTS = ['-analyzeduration', '0', '-loglevel', '0', '-f', 's16le', '-ar', '48000', '-ac', '2'];\nconst FFMPEG_OPUS_ARGUMENTS = [\n\t'-analyzeduration',\n\t'0',\n\t'-loglevel',\n\t'0',\n\t'-acodec',\n\t'libopus',\n\t'-f',\n\t'opus',\n\t'-ar',\n\t'48000',\n\t'-ac',\n\t'2',\n];\n\n/**\n * The different types of stream that can exist within the pipeline\n *\n * @remarks\n * - `Arbitrary` - the type of the stream at this point is unknown.\n *\n * - `Raw` - the stream at this point is s16le PCM.\n *\n * - `OggOpus` - the stream at this point is Opus audio encoded in an Ogg wrapper.\n *\n * - `WebmOpus` - the stream at this point is Opus audio encoded in a WebM wrapper.\n *\n * - `Opus` - the stream at this point is Opus audio, and the stream is in object-mode. This is ready to play.\n */\nexport enum StreamType {\n\tArbitrary = 'arbitrary',\n\tRaw = 'raw',\n\tOggOpus = 'ogg/opus',\n\tWebmOpus = 'webm/opus',\n\tOpus = 'opus',\n}\n\n/**\n * The different types of transformers that can exist within the pipeline\n */\nexport enum TransformerType {\n\tFFmpegPCM = 'ffmpeg pcm',\n\tFFmpegOgg = 'ffmpeg ogg',\n\tOpusEncoder = 'opus encoder',\n\tOpusDecoder = 'opus decoder',\n\tOggOpusDemuxer = 'ogg/opus demuxer',\n\tWebmOpusDemuxer = 'webm/opus demuxer',\n\tInlineVolume = 'volume transformer',\n}\n\n/**\n * Represents a pathway from one stream type to another using a transformer\n */\nexport interface Edge {\n\tfrom: Node;\n\tto: Node;\n\tcost: number;\n\ttransformer: (input: string | Readable) => Readable;\n\ttype: TransformerType;\n}\n\n/**\n * Represents a type of stream within the graph, e.g. an Opus stream, or a stream of raw audio.\n */\nexport class Node {\n\t/**\n\t * The outbound edges from this node\n\t */\n\tpublic readonly edges: Edge[] = [];\n\n\t/**\n\t * The type of stream for this node\n\t */\n\tpublic readonly type: StreamType;\n\n\tpublic constructor(type: StreamType) {\n\t\tthis.type = type;\n\t}\n\n\t/**\n\t * Creates an outbound edge from this node\n\t *\n\t * @param edge - The edge to create\n\t */\n\tpublic addEdge(edge: Omit<Edge, 'from'>) {\n\t\tthis.edges.push({ ...edge, from: this });\n\t}\n}\n\n// Create a node for each stream type\nconst NODES = new Map<StreamType, Node>();\nfor (const streamType of Object.values(StreamType)) {\n\tNODES.set(streamType, new Node(streamType));\n}\n\n/**\n * Gets a node from its stream type\n *\n * @param type - The stream type of the target node\n */\nexport function getNode(type: StreamType) {\n\tconst node = NODES.get(type);\n\tif (!node) throw new Error(`Node type '${type}' does not exist!`);\n\treturn node;\n}\n\ngetNode(StreamType.Raw).addEdge({\n\ttype: TransformerType.OpusEncoder,\n\tto: getNode(StreamType.Opus),\n\tcost: 1.5,\n\ttransformer: () => new prism.opus.Encoder({ rate: 48000, channels: 2, frameSize: 960 }),\n});\n\ngetNode(StreamType.Opus).addEdge({\n\ttype: TransformerType.OpusDecoder,\n\tto: getNode(StreamType.Raw),\n\tcost: 1.5,\n\ttransformer: () => new prism.opus.Decoder({ rate: 48000, channels: 2, frameSize: 960 }),\n});\n\ngetNode(StreamType.OggOpus).addEdge({\n\ttype: TransformerType.OggOpusDemuxer,\n\tto: getNode(StreamType.Opus),\n\tcost: 1,\n\ttransformer: () => new prism.opus.OggDemuxer(),\n});\n\ngetNode(StreamType.WebmOpus).addEdge({\n\ttype: TransformerType.WebmOpusDemuxer,\n\tto: getNode(StreamType.Opus),\n\tcost: 1,\n\ttransformer: () => new prism.opus.WebmDemuxer(),\n});\n\nconst FFMPEG_PCM_EDGE: Omit<Edge, 'from'> = {\n\ttype: TransformerType.FFmpegPCM,\n\tto: getNode(StreamType.Raw),\n\tcost: 2,\n\ttransformer: (input) =>\n\t\tnew prism.FFmpeg({\n\t\t\targs: typeof input === 'string' ? ['-i', input, ...FFMPEG_PCM_ARGUMENTS] : FFMPEG_PCM_ARGUMENTS,\n\t\t}),\n};\n\ngetNode(StreamType.Arbitrary).addEdge(FFMPEG_PCM_EDGE);\ngetNode(StreamType.OggOpus).addEdge(FFMPEG_PCM_EDGE);\ngetNode(StreamType.WebmOpus).addEdge(FFMPEG_PCM_EDGE);\n\ngetNode(StreamType.Raw).addEdge({\n\ttype: TransformerType.InlineVolume,\n\tto: getNode(StreamType.Raw),\n\tcost: 0.5,\n\ttransformer: () => new prism.VolumeTransformer({ type: 's16le' }),\n});\n\n// Try to enable FFmpeg Ogg optimizations\nfunction canEnableFFmpegOptimizations(): boolean {\n\ttry {\n\t\treturn prism.FFmpeg.getInfo().output.includes('--enable-libopus');\n\t} catch {}\n\treturn false;\n}\n\nif (canEnableFFmpegOptimizations()) {\n\tconst FFMPEG_OGG_EDGE: Omit<Edge, 'from'> = {\n\t\ttype: TransformerType.FFmpegOgg,\n\t\tto: getNode(StreamType.OggOpus),\n\t\tcost: 2,\n\t\ttransformer: (input) =>\n\t\t\tnew prism.FFmpeg({\n\t\t\t\targs: typeof input === 'string' ? ['-i', input, ...FFMPEG_OPUS_ARGUMENTS] : FFMPEG_OPUS_ARGUMENTS,\n\t\t\t}),\n\t};\n\tgetNode(StreamType.Arbitrary).addEdge(FFMPEG_OGG_EDGE);\n\t// Include Ogg and WebM as well in case they have different sampling rates or are mono instead of stereo\n\t// at the moment, this will not do anything. However, if/when detection for correct Opus headers is\n\t// implemented, this will help inform the voice engine that it is able to transcode the audio.\n\tgetNode(StreamType.OggOpus).addEdge(FFMPEG_OGG_EDGE);\n\tgetNode(StreamType.WebmOpus).addEdge(FFMPEG_OGG_EDGE);\n}\n\n/**\n * Represents a step in the path from node A to node B.\n */\ninterface Step {\n\t/**\n\t * The next step\n\t */\n\tnext?: Step;\n\n\t/**\n\t * The cost of the steps after this step\n\t */\n\tcost: number;\n\n\t/**\n\t * The edge associated with this step\n\t */\n\tedge?: Edge;\n}\n\n/**\n * Finds the shortest cost path from node A to node B.\n *\n * @param from - The start node\n * @param constraints - Extra validation for a potential solution. Takes a path, returns true if the path is valid.\n * @param goal - The target node\n * @param path - The running path\n * @param depth - The number of remaining recursions\n */\nfunction findPath(\n\tfrom: Node,\n\tconstraints: (path: Edge[]) => boolean,\n\tgoal = getNode(StreamType.Opus),\n\tpath: Edge[] = [],\n\tdepth = 5,\n): Step {\n\tif (from === goal && constraints(path)) {\n\t\treturn { cost: 0 };\n\t} else if (depth === 0) {\n\t\treturn { cost: Infinity };\n\t}\n\n\tlet currentBest: Step | undefined = undefined;\n\tfor (const edge of from.edges) {\n\t\tif (currentBest && edge.cost > currentBest.cost) continue;\n\t\tconst next = findPath(edge.to, constraints, goal, [...path, edge], depth - 1);\n\t\tconst cost = edge.cost + next.cost;\n\t\tif (!currentBest || cost < currentBest.cost) {\n\t\t\tcurrentBest = { cost, edge, next };\n\t\t}\n\t}\n\treturn currentBest ?? { cost: Infinity };\n}\n\n/**\n * Takes the solution from findPath and assembles it into a list of edges\n *\n * @param step - The first step of the path\n */\nfunction constructPipeline(step: Step) {\n\tconst edges = [];\n\tlet current: Step | undefined = step;\n\twhile (current?.edge) {\n\t\tedges.push(current.edge);\n\t\tcurrent = current.next;\n\t}\n\treturn edges;\n}\n\n/**\n * Finds the lowest-cost pipeline to convert the input stream type into an Opus stream\n *\n * @param from - The stream type to start from\n * @param constraint - Extra constraints that may be imposed on potential solution\n */\nexport function findPipeline(from: StreamType, constraint: (path: Edge[]) => boolean) {\n\treturn constructPipeline(findPath(getNode(from), constraint));\n}\n"]}
|
package/dist/audio/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StreamType = exports.PlayerSubscription = exports.createAudioResource = exports.AudioResource = exports.AudioPlayerError = exports.createAudioPlayer = exports.NoSubscriberBehavior = exports.AudioPlayerStatus = exports.AudioPlayer = void 0;
|
|
4
|
-
var AudioPlayer_1 = require("./AudioPlayer");
|
|
5
|
-
Object.defineProperty(exports, "AudioPlayer", { enumerable: true, get: function () { return AudioPlayer_1.AudioPlayer; } });
|
|
6
|
-
Object.defineProperty(exports, "AudioPlayerStatus", { enumerable: true, get: function () { return AudioPlayer_1.AudioPlayerStatus; } });
|
|
7
|
-
Object.defineProperty(exports, "NoSubscriberBehavior", { enumerable: true, get: function () { return AudioPlayer_1.NoSubscriberBehavior; } });
|
|
8
|
-
Object.defineProperty(exports, "createAudioPlayer", { enumerable: true, get: function () { return AudioPlayer_1.createAudioPlayer; } });
|
|
9
|
-
var AudioPlayerError_1 = require("./AudioPlayerError");
|
|
10
|
-
Object.defineProperty(exports, "AudioPlayerError", { enumerable: true, get: function () { return AudioPlayerError_1.AudioPlayerError; } });
|
|
11
|
-
var AudioResource_1 = require("./AudioResource");
|
|
12
|
-
Object.defineProperty(exports, "AudioResource", { enumerable: true, get: function () { return AudioResource_1.AudioResource; } });
|
|
13
|
-
Object.defineProperty(exports, "createAudioResource", { enumerable: true, get: function () { return AudioResource_1.createAudioResource; } });
|
|
14
|
-
var PlayerSubscription_1 = require("./PlayerSubscription");
|
|
15
|
-
Object.defineProperty(exports, "PlayerSubscription", { enumerable: true, get: function () { return PlayerSubscription_1.PlayerSubscription; } });
|
|
16
|
-
var TransformerGraph_1 = require("./TransformerGraph");
|
|
17
|
-
Object.defineProperty(exports, "StreamType", { enumerable: true, get: function () { return TransformerGraph_1.StreamType; } });
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
package/dist/audio/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/audio/index.ts"],"names":[],"mappings":";;;AAAA,6CAYuB;AAXtB,0GAAA,WAAW,OAAA;AACX,gHAAA,iBAAiB,OAAA;AAEjB,mHAAA,oBAAoB,OAAA;AACpB,gHAAA,iBAAiB,OAAA;AASlB,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AAEzB,iDAAqE;AAA5D,8GAAA,aAAa,OAAA;AAAE,oHAAA,mBAAmB,OAAA;AAE3C,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAE3B,uDAAgD;AAAvC,8GAAA,UAAU,OAAA","sourcesContent":["export {\n\tAudioPlayer,\n\tAudioPlayerStatus,\n\tAudioPlayerState,\n\tNoSubscriberBehavior,\n\tcreateAudioPlayer,\n\tAudioPlayerBufferingState,\n\tAudioPlayerIdleState,\n\tAudioPlayerPausedState,\n\tAudioPlayerPlayingState,\n\tCreateAudioPlayerOptions,\n\tAudioPlayerEvents,\n} from './AudioPlayer';\n\nexport { AudioPlayerError } from './AudioPlayerError';\n\nexport { AudioResource, createAudioResource } from './AudioResource';\n\nexport { PlayerSubscription } from './PlayerSubscription';\n\nexport { StreamType } from './TransformerGraph';\n"]}
|
package/dist/joinVoiceChannel.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.joinVoiceChannel = void 0;
|
|
4
|
-
const VoiceConnection_1 = require("./VoiceConnection");
|
|
5
|
-
/**
|
|
6
|
-
* Creates a VoiceConnection to a Discord voice channel.
|
|
7
|
-
*
|
|
8
|
-
* @param voiceChannel - the voice channel to connect to
|
|
9
|
-
* @param options - the options for joining the voice channel
|
|
10
|
-
*/
|
|
11
|
-
function joinVoiceChannel(options) {
|
|
12
|
-
const joinConfig = {
|
|
13
|
-
selfDeaf: true,
|
|
14
|
-
selfMute: false,
|
|
15
|
-
group: 'default',
|
|
16
|
-
...options,
|
|
17
|
-
};
|
|
18
|
-
return VoiceConnection_1.createVoiceConnection(joinConfig, {
|
|
19
|
-
adapterCreator: options.adapterCreator,
|
|
20
|
-
debug: options.debug,
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
exports.joinVoiceChannel = joinVoiceChannel;
|
|
24
|
-
//# sourceMappingURL=joinVoiceChannel.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"joinVoiceChannel.js","sourceRoot":"","sources":["../src/joinVoiceChannel.ts"],"names":[],"mappings":";;;AAAA,uDAA0D;AA0C1D;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,OAA+D;IAC/F,MAAM,UAAU,GAAe;QAC9B,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,KAAK;QACf,KAAK,EAAE,SAAS;QAChB,GAAG,OAAO;KACV,CAAC;IAEF,OAAO,uCAAqB,CAAC,UAAU,EAAE;QACxC,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,KAAK,EAAE,OAAO,CAAC,KAAK;KACpB,CAAC,CAAC;AACJ,CAAC;AAZD,4CAYC","sourcesContent":["import { createVoiceConnection } from './VoiceConnection';\nimport { JoinConfig } from './DataStore';\nimport { DiscordGatewayAdapterCreator } from './util/adapter';\n\n/**\n * The options that can be given when creating a voice connection.\n */\nexport interface CreateVoiceConnectionOptions {\n\t/**\n\t * If true, debug messages will be enabled for the voice connection and its\n\t * related components. Defaults to false.\n\t */\n\tdebug?: boolean;\n\tadapterCreator: DiscordGatewayAdapterCreator;\n}\n\n/**\n * The options that can be given when joining a voice channel.\n */\nexport interface JoinVoiceChannelOptions {\n\t/**\n\t * The ID of the Discord voice channel to join\n\t */\n\tchannelId: string;\n\t/**\n\t * The ID of the guild that the voice channel belongs to\n\t */\n\tguildId: string;\n\t/**\n\t * Whether to join the channel deafened (defaults to true)\n\t */\n\tselfDeaf?: boolean;\n\t/**\n\t * Whether to join the channel muted (defaults to true)\n\t */\n\tselfMute?: boolean;\n\t/**\n\t * An optional group identifier for the voice connection\n\t */\n\tgroup?: string;\n}\n\n/**\n * Creates a VoiceConnection to a Discord voice channel.\n *\n * @param voiceChannel - the voice channel to connect to\n * @param options - the options for joining the voice channel\n */\nexport function joinVoiceChannel(options: JoinVoiceChannelOptions & CreateVoiceConnectionOptions) {\n\tconst joinConfig: JoinConfig = {\n\t\tselfDeaf: true,\n\t\tselfMute: false,\n\t\tgroup: 'default',\n\t\t...options,\n\t};\n\n\treturn createVoiceConnection(joinConfig, {\n\t\tadapterCreator: options.adapterCreator,\n\t\tdebug: options.debug,\n\t});\n}\n"]}
|