@antha/audio 0.0.1
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-CC0 +121 -0
- package/LICENSE-MIT +21 -0
- package/README.md +11 -0
- package/dist/antha-audio.mod.d.ts +28 -0
- package/dist/antha-audio.mod.js +20 -0
- package/dist/audio-file.d.ts +277 -0
- package/dist/audio-file.js +318 -0
- package/dist/audio-player.d.ts +73 -0
- package/dist/audio-player.js +112 -0
- package/dist/codecs.d.ts +292 -0
- package/dist/codecs.js +101 -0
- package/dist/detect-play.d.ts +6 -0
- package/dist/detect-play.js +29 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/package.json +59 -0
- package/sample-files/back_004.mp3 +0 -0
- package/sample-files/confirmation_002.mp3 +0 -0
- package/sample-files/powerUp3 +0 -0
- package/sample-files/powerUp3.mp3 +0 -0
package/LICENSE-CC0
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
CC0 1.0 Universal
|
|
2
|
+
|
|
3
|
+
Creative Commons Legal Code
|
|
4
|
+
|
|
5
|
+
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
|
6
|
+
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
|
7
|
+
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
|
8
|
+
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
|
9
|
+
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
|
10
|
+
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
|
11
|
+
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
|
12
|
+
HEREUNDER.
|
|
13
|
+
|
|
14
|
+
Statement of Purpose
|
|
15
|
+
|
|
16
|
+
The laws of most jurisdictions throughout the world automatically confer
|
|
17
|
+
exclusive Copyright and Related Rights (defined below) upon the creator
|
|
18
|
+
and subsequent owner(s) (each and all, an "owner") of an original work of
|
|
19
|
+
authorship and/or a database (each, a "Work").
|
|
20
|
+
|
|
21
|
+
Certain owners wish to permanently relinquish those rights to a Work for
|
|
22
|
+
the purpose of contributing to a commons of creative, cultural and
|
|
23
|
+
scientific works ("Commons") that the public can reliably and without fear
|
|
24
|
+
of later claims of infringement build upon, modify, incorporate in other
|
|
25
|
+
works, reuse and redistribute as freely as possible in any form whatsoever
|
|
26
|
+
and for any purposes, including without limitation commercial purposes.
|
|
27
|
+
These owners may contribute to the Commons to promote the ideal of a free
|
|
28
|
+
culture and the further production of creative, cultural and scientific
|
|
29
|
+
works, or to gain reputation or greater distribution for their Work in
|
|
30
|
+
part through the use and efforts of others.
|
|
31
|
+
|
|
32
|
+
For these and/or other purposes and motivations, and without any
|
|
33
|
+
expectation of additional consideration or compensation, the person
|
|
34
|
+
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
|
35
|
+
is an owner of Copyright and Related Rights in the Work, voluntarily
|
|
36
|
+
elects to apply CC0 to the Work and publicly distribute the Work under its
|
|
37
|
+
terms, with knowledge of his or her Copyright and Related Rights in the
|
|
38
|
+
Work and the meaning and intended legal effect of CC0 on those rights.
|
|
39
|
+
|
|
40
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
|
41
|
+
protected by copyright and related or neighboring rights ("Copyright and
|
|
42
|
+
Related Rights"). Copyright and Related Rights include, but are not
|
|
43
|
+
limited to, the following:
|
|
44
|
+
|
|
45
|
+
i. the right to reproduce, adapt, distribute, perform, display,
|
|
46
|
+
communicate, and translate a Work;
|
|
47
|
+
ii. moral rights retained by the original author(s) and/or performer(s);
|
|
48
|
+
iii. publicity and privacy rights pertaining to a person's image or
|
|
49
|
+
likeness depicted in a Work;
|
|
50
|
+
iv. rights protecting against unfair competition in regards to a Work,
|
|
51
|
+
subject to the limitations in paragraph 4(a), below;
|
|
52
|
+
v. rights protecting the extraction, dissemination, use and reuse of data
|
|
53
|
+
in a Work;
|
|
54
|
+
vi. database rights (such as those arising under Directive 96/9/EC of the
|
|
55
|
+
European Parliament and of the Council of 11 March 1996 on the legal
|
|
56
|
+
protection of databases, and under any national implementation
|
|
57
|
+
thereof, including any amended or successor version of such
|
|
58
|
+
directive); and
|
|
59
|
+
vii. other similar, equivalent or corresponding rights throughout the
|
|
60
|
+
world based on applicable law or treaty, and any national
|
|
61
|
+
implementations thereof.
|
|
62
|
+
|
|
63
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention
|
|
64
|
+
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
|
65
|
+
irrevocably and unconditionally waives, abandons, and surrenders all of
|
|
66
|
+
Affirmer's Copyright and Related Rights and associated claims and causes
|
|
67
|
+
of action, whether now known or unknown (including existing as well as
|
|
68
|
+
future claims and causes of action), in the Work (i) in all territories
|
|
69
|
+
worldwide, (ii) for the maximum duration provided by applicable law or
|
|
70
|
+
treaty (including future time extensions), (iii) in any current or future
|
|
71
|
+
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
|
72
|
+
including without limitation commercial, advertising or promotional
|
|
73
|
+
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
|
74
|
+
member of the public at large and to the detriment of Affirmer's heirs and
|
|
75
|
+
successors, fully intending that such Waiver shall not be subject to
|
|
76
|
+
revocation, rescission, cancellation, termination, or any other legal or
|
|
77
|
+
equitable action to disrupt the quiet enjoyment of the Work by the public
|
|
78
|
+
as contemplated by Affirmer's express Statement of Purpose.
|
|
79
|
+
|
|
80
|
+
3. Public License Fallback. Should any part of the Waiver for any reason
|
|
81
|
+
be judged legally invalid or ineffective under applicable law, then the
|
|
82
|
+
Waiver shall be preserved to the maximum extent permitted taking into
|
|
83
|
+
account Affirmer's express Statement of Purpose. In addition, to the
|
|
84
|
+
extent the Waiver is so judged Affirmer hereby grants to each affected
|
|
85
|
+
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
|
86
|
+
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
|
87
|
+
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
|
88
|
+
maximum duration provided by applicable law or treaty (including future
|
|
89
|
+
time extensions), (iii) in any current or future medium and for any number
|
|
90
|
+
of copies, and (iv) for any purpose whatsoever, including without
|
|
91
|
+
limitation commercial, advertising or promotional purposes (the
|
|
92
|
+
"License"). The License shall be deemed effective as of the date CC0 was
|
|
93
|
+
applied by Affirmer to the Work. Should any part of the License for any
|
|
94
|
+
reason be judged legally invalid or ineffective under applicable law, such
|
|
95
|
+
partial invalidity or ineffectiveness shall not invalidate the remainder
|
|
96
|
+
of the License, and in such case Affirmer hereby affirms that he or she
|
|
97
|
+
will not (i) exercise any of his or her remaining Copyright and Related
|
|
98
|
+
Rights in the Work or (ii) assert any associated claims and causes of
|
|
99
|
+
action with respect to the Work, in either case contrary to Affirmer's
|
|
100
|
+
express Statement of Purpose.
|
|
101
|
+
|
|
102
|
+
4. Limitations and Disclaimers.
|
|
103
|
+
|
|
104
|
+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
|
105
|
+
surrendered, licensed or otherwise affected by this document.
|
|
106
|
+
b. Affirmer offers the Work as-is and makes no representations or
|
|
107
|
+
warranties of any kind concerning the Work, express, implied,
|
|
108
|
+
statutory or otherwise, including without limitation warranties of
|
|
109
|
+
title, merchantability, fitness for a particular purpose, non
|
|
110
|
+
infringement, or the absence of latent or other defects, accuracy, or
|
|
111
|
+
the present or absence of errors, whether or not discoverable, all to
|
|
112
|
+
the greatest extent permissible under applicable law.
|
|
113
|
+
c. Affirmer disclaims responsibility for clearing rights of other persons
|
|
114
|
+
that may apply to the Work or any use thereof, including without
|
|
115
|
+
limitation any person's Copyright and Related Rights in the Work.
|
|
116
|
+
Further, Affirmer disclaims responsibility for obtaining any necessary
|
|
117
|
+
consents, permissions or other rights required for any use of the
|
|
118
|
+
Work.
|
|
119
|
+
d. Affirmer understands and acknowledges that Creative Commons is not a
|
|
120
|
+
party to this document and has no duty or obligation with respect to
|
|
121
|
+
this CC0 or use of the Work.
|
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 electrovir
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type PartialWithUndefined } from '@augment-vir/common';
|
|
2
|
+
import { AudioPlayer, type AudioPlayerOptions } from './audio-player.js';
|
|
3
|
+
/**
|
|
4
|
+
* State for {@link createAnthaAudioMod}.
|
|
5
|
+
*
|
|
6
|
+
* @category Internal
|
|
7
|
+
*/
|
|
8
|
+
export type AnthaAudioState = {
|
|
9
|
+
audioPlayer: AudioPlayer;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Options for {@link createAnthaAudioMod}.
|
|
13
|
+
*
|
|
14
|
+
* @category Internal
|
|
15
|
+
*/
|
|
16
|
+
export type AnthaAudioModOptions = PartialWithUndefined<AudioPlayerOptions>;
|
|
17
|
+
/**
|
|
18
|
+
* A pre-built mod for playing audio files.
|
|
19
|
+
*
|
|
20
|
+
* @category Pre-Built Mods
|
|
21
|
+
*/
|
|
22
|
+
export declare function createAnthaAudioMod(audioPlayerOptions?: Readonly<AnthaAudioModOptions>): import("@antha/engine").AnthaMod<NoInfer<AnthaAudioState>>;
|
|
23
|
+
/**
|
|
24
|
+
* The mod created by {@link createAnthaAudioMod}.
|
|
25
|
+
*
|
|
26
|
+
* @category Internal
|
|
27
|
+
*/
|
|
28
|
+
export type AnthaAudioMod = ReturnType<typeof createAnthaAudioMod>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineAnthaMod } from '@antha/engine';
|
|
2
|
+
import { AudioPlayer } from './audio-player.js';
|
|
3
|
+
/**
|
|
4
|
+
* A pre-built mod for playing audio files.
|
|
5
|
+
*
|
|
6
|
+
* @category Pre-Built Mods
|
|
7
|
+
*/
|
|
8
|
+
export function createAnthaAudioMod(audioPlayerOptions = {}) {
|
|
9
|
+
return defineAnthaMod({
|
|
10
|
+
modName: 'antha-audio',
|
|
11
|
+
async cleanup({ state }) {
|
|
12
|
+
await state.audioPlayer?.destroy();
|
|
13
|
+
},
|
|
14
|
+
execute({ state }) {
|
|
15
|
+
if (!state.audioPlayer) {
|
|
16
|
+
state.audioPlayer = new AudioPlayer(audioPlayerOptions);
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { type PartialWithUndefined, type SelectFrom } from '@augment-vir/common';
|
|
2
|
+
import { ListenTarget } from 'typed-event-target';
|
|
3
|
+
import { type Codec } from './codecs.js';
|
|
4
|
+
/**
|
|
5
|
+
* Accepted types for the {@link AudioFile} source param `AudioFileParams.sources`).
|
|
6
|
+
*
|
|
7
|
+
* @category Internal
|
|
8
|
+
*/
|
|
9
|
+
export type AudioFileSource =
|
|
10
|
+
/** The URL of the audio file. The codec will be determined automatically by the file name. */
|
|
11
|
+
string | {
|
|
12
|
+
url: string;
|
|
13
|
+
/** Force a specific codec for this file. */
|
|
14
|
+
codec: Codec;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Init params for {@link AudioFile}. When {@link AudioFile} instances are constructed internally by
|
|
18
|
+
* `AudioPlayer`, only a subset of these parameters can be / must be manually provided.
|
|
19
|
+
*
|
|
20
|
+
* @category Internal
|
|
21
|
+
*/
|
|
22
|
+
export type AudioFileParams = Readonly<{
|
|
23
|
+
/**
|
|
24
|
+
* An array of possible source file URLs. The first one that is supported by the current
|
|
25
|
+
* browser will be used.
|
|
26
|
+
*/
|
|
27
|
+
sources: ReadonlyArray<AudioFileSource> | AudioFileSource;
|
|
28
|
+
} & PartialWithUndefined<{
|
|
29
|
+
/**
|
|
30
|
+
* Override the used `fetch` implementation.
|
|
31
|
+
*
|
|
32
|
+
* @default globalThis.fetch
|
|
33
|
+
*/
|
|
34
|
+
fetch: (url: string) => Promise<Pick<Response, 'arrayBuffer'>>;
|
|
35
|
+
/** A value between `0` and `1` to control volume. */
|
|
36
|
+
volume: number;
|
|
37
|
+
outputNode: AudioNode;
|
|
38
|
+
audioContext: BaseAudioContext;
|
|
39
|
+
audioCache: AudioFileCache;
|
|
40
|
+
/**
|
|
41
|
+
* Any audio nodes to chain together. They will automatically be connected together in
|
|
42
|
+
* sequential order.
|
|
43
|
+
*/
|
|
44
|
+
createEffects: (audioContext: BaseAudioContext) => ReadonlyArray<AudioNode> | undefined | void;
|
|
45
|
+
}>>;
|
|
46
|
+
/**
|
|
47
|
+
* Create a key for a given audio file config as a cache key.
|
|
48
|
+
*
|
|
49
|
+
* @category Internal
|
|
50
|
+
*/
|
|
51
|
+
export declare function createAudioSourceKey(params: Readonly<SelectFrom<AudioFileParams, {
|
|
52
|
+
volume: true;
|
|
53
|
+
sources: true;
|
|
54
|
+
}>>): string;
|
|
55
|
+
declare const AudioFilePlayEndEvent_base: (new (eventInitDict?: EventInit) => Event & import("typed-event-target").TypedEvent<"audio-file-play-end">) & Pick<{
|
|
56
|
+
new (type: string, eventInitDict?: EventInit): Event;
|
|
57
|
+
prototype: Event;
|
|
58
|
+
readonly NONE: 0;
|
|
59
|
+
readonly CAPTURING_PHASE: 1;
|
|
60
|
+
readonly AT_TARGET: 2;
|
|
61
|
+
readonly BUBBLING_PHASE: 3;
|
|
62
|
+
}, "prototype" | "NONE" | "CAPTURING_PHASE" | "AT_TARGET" | "BUBBLING_PHASE"> & Pick<import("typed-event-target").TypedEvent<"audio-file-play-end">, "type">;
|
|
63
|
+
/**
|
|
64
|
+
* Emitted when an {@link AudioFile} finishes playing.
|
|
65
|
+
*
|
|
66
|
+
* @category Events
|
|
67
|
+
*/
|
|
68
|
+
export declare class AudioFilePlayEndEvent extends AudioFilePlayEndEvent_base {
|
|
69
|
+
}
|
|
70
|
+
declare const AudioFilePlayStartEvent_base: (new (eventInitDict?: EventInit) => Event & import("typed-event-target").TypedEvent<"audio-file-play-start">) & Pick<{
|
|
71
|
+
new (type: string, eventInitDict?: EventInit): Event;
|
|
72
|
+
prototype: Event;
|
|
73
|
+
readonly NONE: 0;
|
|
74
|
+
readonly CAPTURING_PHASE: 1;
|
|
75
|
+
readonly AT_TARGET: 2;
|
|
76
|
+
readonly BUBBLING_PHASE: 3;
|
|
77
|
+
}, "prototype" | "NONE" | "CAPTURING_PHASE" | "AT_TARGET" | "BUBBLING_PHASE"> & Pick<import("typed-event-target").TypedEvent<"audio-file-play-start">, "type">;
|
|
78
|
+
/**
|
|
79
|
+
* Emitted when an {@link AudioFile} starts playing.
|
|
80
|
+
*
|
|
81
|
+
* @category Events
|
|
82
|
+
*/
|
|
83
|
+
export declare class AudioFilePlayStartEvent extends AudioFilePlayStartEvent_base {
|
|
84
|
+
}
|
|
85
|
+
declare const AudioFileDestroyedEvent_base: (new (eventInitDict?: EventInit) => Event & import("typed-event-target").TypedEvent<"audio-file-destroyed">) & Pick<{
|
|
86
|
+
new (type: string, eventInitDict?: EventInit): Event;
|
|
87
|
+
prototype: Event;
|
|
88
|
+
readonly NONE: 0;
|
|
89
|
+
readonly CAPTURING_PHASE: 1;
|
|
90
|
+
readonly AT_TARGET: 2;
|
|
91
|
+
readonly BUBBLING_PHASE: 3;
|
|
92
|
+
}, "prototype" | "NONE" | "CAPTURING_PHASE" | "AT_TARGET" | "BUBBLING_PHASE"> & Pick<import("typed-event-target").TypedEvent<"audio-file-destroyed">, "type">;
|
|
93
|
+
/**
|
|
94
|
+
* Emitted when an {@link AudioFile} is destroyed.
|
|
95
|
+
*
|
|
96
|
+
* @category Events
|
|
97
|
+
*/
|
|
98
|
+
export declare class AudioFileDestroyedEvent extends AudioFileDestroyedEvent_base {
|
|
99
|
+
}
|
|
100
|
+
declare const AudioFileLoadEvent_base: (new (eventInitDict?: EventInit) => Event & import("typed-event-target").TypedEvent<"audio-file-load">) & Pick<{
|
|
101
|
+
new (type: string, eventInitDict?: EventInit): Event;
|
|
102
|
+
prototype: Event;
|
|
103
|
+
readonly NONE: 0;
|
|
104
|
+
readonly CAPTURING_PHASE: 1;
|
|
105
|
+
readonly AT_TARGET: 2;
|
|
106
|
+
readonly BUBBLING_PHASE: 3;
|
|
107
|
+
}, "prototype" | "NONE" | "CAPTURING_PHASE" | "AT_TARGET" | "BUBBLING_PHASE"> & Pick<import("typed-event-target").TypedEvent<"audio-file-load">, "type">;
|
|
108
|
+
/**
|
|
109
|
+
* Emitted when an {@link AudioFile} is loaded.
|
|
110
|
+
*
|
|
111
|
+
* @category Events
|
|
112
|
+
*/
|
|
113
|
+
export declare class AudioFileLoadEvent extends AudioFileLoadEvent_base {
|
|
114
|
+
}
|
|
115
|
+
declare const AudioFileErrorEvent_base: (new (eventInitDict: {
|
|
116
|
+
bubbles?: boolean;
|
|
117
|
+
cancelable?: boolean;
|
|
118
|
+
composed?: boolean;
|
|
119
|
+
detail: Error;
|
|
120
|
+
}) => import("typed-event-target").TypedCustomEvent<Error, "audio-file-error">) & Pick<{
|
|
121
|
+
new (type: string, eventInitDict?: EventInit): Event;
|
|
122
|
+
prototype: Event;
|
|
123
|
+
readonly NONE: 0;
|
|
124
|
+
readonly CAPTURING_PHASE: 1;
|
|
125
|
+
readonly AT_TARGET: 2;
|
|
126
|
+
readonly BUBBLING_PHASE: 3;
|
|
127
|
+
}, "prototype" | "NONE" | "CAPTURING_PHASE" | "AT_TARGET" | "BUBBLING_PHASE"> & Pick<import("typed-event-target").TypedCustomEvent<Error, "audio-file-error">, "type">;
|
|
128
|
+
/**
|
|
129
|
+
* Emitted when an {@link AudioFile} encounters an error.
|
|
130
|
+
*
|
|
131
|
+
* @category Events
|
|
132
|
+
*/
|
|
133
|
+
export declare class AudioFileErrorEvent extends AudioFileErrorEvent_base {
|
|
134
|
+
}
|
|
135
|
+
declare const PlayingEnabledEvent_base: (new (eventInitDict?: EventInit) => Event & import("typed-event-target").TypedEvent<"playing-enabled">) & Pick<{
|
|
136
|
+
new (type: string, eventInitDict?: EventInit): Event;
|
|
137
|
+
prototype: Event;
|
|
138
|
+
readonly NONE: 0;
|
|
139
|
+
readonly CAPTURING_PHASE: 1;
|
|
140
|
+
readonly AT_TARGET: 2;
|
|
141
|
+
readonly BUBBLING_PHASE: 3;
|
|
142
|
+
}, "prototype" | "NONE" | "CAPTURING_PHASE" | "AT_TARGET" | "BUBBLING_PHASE"> & Pick<import("typed-event-target").TypedEvent<"playing-enabled">, "type">;
|
|
143
|
+
/**
|
|
144
|
+
* When this event is fired, it indicates that we've detected that playing sounds has now been
|
|
145
|
+
* enabled in the current session.
|
|
146
|
+
*
|
|
147
|
+
* @category Events
|
|
148
|
+
*/
|
|
149
|
+
export declare class PlayingEnabledEvent extends PlayingEnabledEvent_base {
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* All events that can be emitted from an {@link AudioFile} instance.
|
|
153
|
+
*
|
|
154
|
+
* @category Internal
|
|
155
|
+
*/
|
|
156
|
+
export type AllAudioFileEvents = AudioFilePlayEndEvent | AudioFilePlayStartEvent | AudioFileLoadEvent | AudioFileErrorEvent | PlayingEnabledEvent;
|
|
157
|
+
/**
|
|
158
|
+
* Type interface for the audio file cache.
|
|
159
|
+
*
|
|
160
|
+
* @category Internal
|
|
161
|
+
*/
|
|
162
|
+
export type AudioFileCache = {
|
|
163
|
+
[UrlOrBase64 in string]: Promise<{
|
|
164
|
+
/** Current audio files that are using this url. */
|
|
165
|
+
using: Set<AudioFile>;
|
|
166
|
+
buffer: AudioBuffer;
|
|
167
|
+
}>;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Allows creating an array of `AudioNode` instances ("effects") by passing the given `AudioContext`
|
|
171
|
+
* to `createEffects`. The effects created by `createEffects`, if any, are then sequentially
|
|
172
|
+
* connected to each other and finally to the `originalOutputNode`. If effects are created, the
|
|
173
|
+
* first one is returned as `outputNode` so all future playback can be routed through all the
|
|
174
|
+
* effects. If no effects were created, `originalOutputNode` is returned as `outputNode`.
|
|
175
|
+
*
|
|
176
|
+
* Some possible connection chains:
|
|
177
|
+
*
|
|
178
|
+
* - 3 effects created: `effects[0]` (`outputNode`) -> `effects[1]` -> `effects[2]` ->
|
|
179
|
+
* `originalOutputNode`
|
|
180
|
+
* - 1 effect created: `effects[0]` (`outputNode`) -> `originalOutputNode`
|
|
181
|
+
* - No effects created: `originalOutputNode` (`outputNode`)
|
|
182
|
+
*
|
|
183
|
+
* @category Internal
|
|
184
|
+
*/
|
|
185
|
+
export declare function setupEffects(audioContext: Readonly<BaseAudioContext>, originalOutputNode: Readonly<AudioNode>, createEffects: AudioFileParams['createEffects']): {
|
|
186
|
+
/** The node that all future playback should be connected to. */
|
|
187
|
+
outputNode: AudioNode;
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* An individual audio file.
|
|
191
|
+
*
|
|
192
|
+
* @category Internal
|
|
193
|
+
*/
|
|
194
|
+
export declare class AudioFile extends ListenTarget<AllAudioFileEvents> {
|
|
195
|
+
private readonly params;
|
|
196
|
+
/**
|
|
197
|
+
* The url or base64 string chosen from the originally provided list of sources that is most
|
|
198
|
+
* compatible with the current browser. This is what will be played.
|
|
199
|
+
*/
|
|
200
|
+
readonly urlOrBase64: string;
|
|
201
|
+
/**
|
|
202
|
+
* - `undefined` indicates that loading has not yet started (or has been unloaded).
|
|
203
|
+
* - `Promise` means that loading has begun (and might be finished).
|
|
204
|
+
*/
|
|
205
|
+
protected loadPromise: ReturnType<typeof this.load> | undefined;
|
|
206
|
+
/**
|
|
207
|
+
* The `AudioNode` that all playback should route to. If effects are provided, this will be the
|
|
208
|
+
* first effect (because it'll sequentially route through all of the following effects,
|
|
209
|
+
* eventually into the final volume `GainNode`). If no effects are provided, this will simply be
|
|
210
|
+
* the internal volume `GainNode`.
|
|
211
|
+
*/
|
|
212
|
+
protected readonly outputNode: AudioNode;
|
|
213
|
+
/**
|
|
214
|
+
* `AudioContext` for creating and playing audio nodes. This is automatically provided by a
|
|
215
|
+
* parent `AudioPlayer`.
|
|
216
|
+
*/
|
|
217
|
+
protected readonly audioContext: BaseAudioContext;
|
|
218
|
+
/**
|
|
219
|
+
* Cache of all loaded audio files. When an {@link AudioFile} instance is part of an
|
|
220
|
+
* `AudioPlayer`, this cache will be provided by the parent `AudioPlayer` and shared between all
|
|
221
|
+
* {@link AudioFile} instances.
|
|
222
|
+
*/
|
|
223
|
+
protected readonly audioCache: AudioFileCache;
|
|
224
|
+
/**
|
|
225
|
+
* Internal fetch implementation to use. This can be overridden with `AudioFileParams.fetch`.
|
|
226
|
+
*
|
|
227
|
+
* @default globalThis.fetch
|
|
228
|
+
*/
|
|
229
|
+
protected readonly fetch: NonNullable<AudioFileParams['fetch']>;
|
|
230
|
+
/**
|
|
231
|
+
* If `true`, indicates that this {@link AudioFile} instance (or another instance within the same
|
|
232
|
+
* `AudioPlayer`) has detected that the current browser session is allowing audio playback. Most
|
|
233
|
+
* browsers these days block audio on initial page load until the user has interacted with the
|
|
234
|
+
* page.
|
|
235
|
+
*/
|
|
236
|
+
readonly isAudioAllowed: boolean;
|
|
237
|
+
/**
|
|
238
|
+
* Indicates if the {@link AudioFile} has been destroyed. If it has, this file should not be
|
|
239
|
+
* interacted with anymore. This is set by running {@link AudioFile.destroy}.
|
|
240
|
+
*/
|
|
241
|
+
readonly isDestroyed: boolean;
|
|
242
|
+
readonly gainNode: GainNode;
|
|
243
|
+
readonly sourceKey: string;
|
|
244
|
+
constructor(params: AudioFileParams);
|
|
245
|
+
/**
|
|
246
|
+
* Load the audio file so it's ready to play. This will automatically be called on the first
|
|
247
|
+
* {@link AudioFile.play} call, but doing so will introduce latency to the first play.
|
|
248
|
+
*/
|
|
249
|
+
load(): ReturnType<typeof this.loadAudioBuffer>;
|
|
250
|
+
/**
|
|
251
|
+
* Play the audio file. If the audio file has not been loaded yet, it will be loaded before
|
|
252
|
+
* playing. If audio playing is disabled (which these days is often the case until the user
|
|
253
|
+
* interacts with the page), the file will not play. This resolves when the audio file has
|
|
254
|
+
* finished playing.
|
|
255
|
+
*
|
|
256
|
+
* @returns Whether or not the audio file was actually played. The audio file will not be played
|
|
257
|
+
* if audio is currently disabled.
|
|
258
|
+
*/
|
|
259
|
+
play(): Promise<boolean>;
|
|
260
|
+
/** Destroys this audio file entirely; it cannot be used anymore. */
|
|
261
|
+
destroy(): Promise<void>;
|
|
262
|
+
/**
|
|
263
|
+
* Load the audio file's `AudioBuffer` through one of the following:
|
|
264
|
+
*
|
|
265
|
+
* - Retrieving it from the cache (if it exists) using {@link AudioFile.urlOrBase64}
|
|
266
|
+
* - Parsing the base64 encoded source string (if the source string is encoded base64)
|
|
267
|
+
* - Fetching the file URL from the internet
|
|
268
|
+
*
|
|
269
|
+
* If a cache entry for this file does not already exist, this will create one.
|
|
270
|
+
*/
|
|
271
|
+
protected loadAudioBuffer(): Promise<AudioBuffer>;
|
|
272
|
+
/** Load the audio file's `ArrayBuffer` from its base64 encoded source string. */
|
|
273
|
+
protected loadBase64(): ArrayBuffer;
|
|
274
|
+
/** Load the audio file's `ArrayBuffer` from its source URL. */
|
|
275
|
+
protected loadFromUrl(): Promise<ArrayBuffer>;
|
|
276
|
+
}
|
|
277
|
+
export {};
|