@spcsn/taro 0.1.0
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/README.md +12 -0
- package/dist/index.js +147 -0
- package/dist/index.js.map +1 -0
- package/index.js +9 -0
- package/package.json +86 -0
- package/types/api/ad/index.d.ts +197 -0
- package/types/api/ai/face.d.ts +133 -0
- package/types/api/ai/inference.d.ts +129 -0
- package/types/api/ai/visionkit.d.ts +874 -0
- package/types/api/alipay/index.d.ts +69 -0
- package/types/api/base/crypto.d.ts +104 -0
- package/types/api/base/debug.d.ts +329 -0
- package/types/api/base/env.d.ts +19 -0
- package/types/api/base/index.d.ts +102 -0
- package/types/api/base/performance.d.ts +258 -0
- package/types/api/base/system.d.ts +742 -0
- package/types/api/base/update.d.ts +130 -0
- package/types/api/base/weapp/app-event.d.ts +265 -0
- package/types/api/base/weapp/life-cycle.d.ts +155 -0
- package/types/api/canvas/index.d.ts +2162 -0
- package/types/api/cloud/index.d.ts +2622 -0
- package/types/api/data-analysis/index.d.ts +122 -0
- package/types/api/device/accelerometer.d.ts +102 -0
- package/types/api/device/accessibility.d.ts +26 -0
- package/types/api/device/battery.d.ts +46 -0
- package/types/api/device/bluetooth-ble.d.ts +601 -0
- package/types/api/device/bluetooth-peripheral.d.ts +430 -0
- package/types/api/device/bluetooth.d.ts +463 -0
- package/types/api/device/calendar.d.ts +98 -0
- package/types/api/device/clipboard.d.ts +81 -0
- package/types/api/device/compass.d.ts +105 -0
- package/types/api/device/contact.d.ts +110 -0
- package/types/api/device/gyroscope.d.ts +85 -0
- package/types/api/device/iBeacon.d.ts +168 -0
- package/types/api/device/keyboard.d.ts +97 -0
- package/types/api/device/memory.d.ts +52 -0
- package/types/api/device/motion.d.ts +88 -0
- package/types/api/device/network.d.ts +172 -0
- package/types/api/device/nfc.d.ts +1238 -0
- package/types/api/device/phone.d.ts +30 -0
- package/types/api/device/scan.d.ts +111 -0
- package/types/api/device/screen.d.ts +217 -0
- package/types/api/device/sms.d.ts +26 -0
- package/types/api/device/vibrate.d.ts +51 -0
- package/types/api/device/wifi.d.ts +301 -0
- package/types/api/ext/index.d.ts +64 -0
- package/types/api/files/index.d.ts +1472 -0
- package/types/api/framework/index.d.ts +51 -0
- package/types/api/location/index.d.ts +517 -0
- package/types/api/media/audio.d.ts +1013 -0
- package/types/api/media/background-audio.d.ts +291 -0
- package/types/api/media/camera.d.ts +207 -0
- package/types/api/media/editor.d.ts +239 -0
- package/types/api/media/image.d.ts +469 -0
- package/types/api/media/live.d.ts +461 -0
- package/types/api/media/map.d.ts +638 -0
- package/types/api/media/media-recorder.d.ts +117 -0
- package/types/api/media/recorder.d.ts +317 -0
- package/types/api/media/video-decoder.d.ts +117 -0
- package/types/api/media/video-processing.d.ts +84 -0
- package/types/api/media/video.d.ts +527 -0
- package/types/api/media/voip.d.ts +393 -0
- package/types/api/navigate/index.d.ts +327 -0
- package/types/api/network/download.d.ts +173 -0
- package/types/api/network/mdns.d.ts +191 -0
- package/types/api/network/request.d.ts +480 -0
- package/types/api/network/tcp.d.ts +181 -0
- package/types/api/network/udp.d.ts +218 -0
- package/types/api/network/upload.d.ts +201 -0
- package/types/api/network/websocket.d.ts +383 -0
- package/types/api/open-api/account.d.ts +51 -0
- package/types/api/open-api/address.d.ts +68 -0
- package/types/api/open-api/authorize.d.ts +80 -0
- package/types/api/open-api/card.d.ts +110 -0
- package/types/api/open-api/channels.d.ts +225 -0
- package/types/api/open-api/customer-service.d.ts +45 -0
- package/types/api/open-api/device-voip.d.ts +103 -0
- package/types/api/open-api/facial.d.ts +98 -0
- package/types/api/open-api/favorites.d.ts +101 -0
- package/types/api/open-api/group.d.ts +59 -0
- package/types/api/open-api/invoice.d.ts +87 -0
- package/types/api/open-api/license-plate.d.ts +27 -0
- package/types/api/open-api/login.d.ts +115 -0
- package/types/api/open-api/my-miniprogram.d.ts +28 -0
- package/types/api/open-api/privacy.d.ts +107 -0
- package/types/api/open-api/redpackage.d.ts +24 -0
- package/types/api/open-api/settings.d.ts +174 -0
- package/types/api/open-api/soter.d.ts +184 -0
- package/types/api/open-api/sticker.d.ts +83 -0
- package/types/api/open-api/subscribe-message.d.ts +305 -0
- package/types/api/open-api/user-info.d.ts +182 -0
- package/types/api/open-api/werun.d.ts +101 -0
- package/types/api/payment/index.d.ts +119 -0
- package/types/api/qq/index.d.ts +354 -0
- package/types/api/route/index.d.ts +324 -0
- package/types/api/share/index.d.ts +354 -0
- package/types/api/skyline/index.d.ts +345 -0
- package/types/api/storage/background-fetch.d.ts +131 -0
- package/types/api/storage/cache-manager.d.ts +249 -0
- package/types/api/storage/index.d.ts +405 -0
- package/types/api/swan/bookshelf.d.ts +307 -0
- package/types/api/swan/download-package.d.ts +80 -0
- package/types/api/swan/index.d.ts +251 -0
- package/types/api/swan/pay.d.ts +139 -0
- package/types/api/taro.extend.d.ts +233 -0
- package/types/api/taro.hooks.d.ts +148 -0
- package/types/api/ui/animation.d.ts +427 -0
- package/types/api/ui/background.d.ts +69 -0
- package/types/api/ui/custom-component.d.ts +23 -0
- package/types/api/ui/fonts.d.ts +77 -0
- package/types/api/ui/interaction.d.ts +281 -0
- package/types/api/ui/menu.d.ts +29 -0
- package/types/api/ui/navigation-bar.d.ts +130 -0
- package/types/api/ui/pull-down-refresh.d.ts +50 -0
- package/types/api/ui/scroll.d.ts +114 -0
- package/types/api/ui/sticky.d.ts +32 -0
- package/types/api/ui/tab-bar.d.ts +196 -0
- package/types/api/ui/window.d.ts +71 -0
- package/types/api/worker/index.d.ts +83 -0
- package/types/api/wxml/index.d.ts +540 -0
- package/types/compile/compiler.d.ts +32 -0
- package/types/compile/config/h5.d.ts +134 -0
- package/types/compile/config/harmony.d.ts +118 -0
- package/types/compile/config/index.d.ts +8 -0
- package/types/compile/config/manifest.d.ts +155 -0
- package/types/compile/config/mini.d.ts +118 -0
- package/types/compile/config/plugin.d.ts +34 -0
- package/types/compile/config/project.d.ts +338 -0
- package/types/compile/config/rn.d.ts +85 -0
- package/types/compile/config/util.d.ts +179 -0
- package/types/compile/hooks.d.ts +13 -0
- package/types/compile/index.d.ts +11 -0
- package/types/compile/viteCompilerContext.d.ts +167 -0
- package/types/global.d.ts +428 -0
- package/types/index.d.ts +190 -0
- package/types/taro.api.d.ts +130 -0
- package/types/taro.component.d.ts +168 -0
- package/types/taro.config.d.ts +712 -0
- package/types/taro.lifecycle.d.ts +220 -0
- package/types/taro.runtime.d.ts +9 -0
|
@@ -0,0 +1,1013 @@
|
|
|
1
|
+
import Taro from '../../index'
|
|
2
|
+
|
|
3
|
+
declare module '../../index' {
|
|
4
|
+
namespace stopVoice {
|
|
5
|
+
interface Option {
|
|
6
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
7
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
8
|
+
/** 接口调用失败的回调函数 */
|
|
9
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
10
|
+
/** 接口调用成功的回调函数 */
|
|
11
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
namespace setInnerAudioOption {
|
|
16
|
+
interface Option {
|
|
17
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
18
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
19
|
+
/** 接口调用失败的回调函数 */
|
|
20
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
21
|
+
/** 是否与其他音频混播,设置为 true 之后,不会终止其他应用或微信内的音乐 */
|
|
22
|
+
mixWithOther?: boolean
|
|
23
|
+
/** (仅在 iOS 生效)是否遵循静音开关,设置为 false 之后,即使是在静音模式下,也能播放声音 */
|
|
24
|
+
obeyMuteSwitch?: boolean
|
|
25
|
+
/** 接口调用成功的回调函数 */
|
|
26
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
namespace playVoice {
|
|
31
|
+
interface Option {
|
|
32
|
+
/** 需要播放的语音文件的文件路径 */
|
|
33
|
+
filePath: string
|
|
34
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
35
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
36
|
+
/** 指定录音时长,到达指定的录音时长后会自动停止录音,单位:秒 */
|
|
37
|
+
duration?: number
|
|
38
|
+
/** 接口调用失败的回调函数 */
|
|
39
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
40
|
+
/** 接口调用成功的回调函数 */
|
|
41
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
namespace pauseVoice {
|
|
46
|
+
interface Option {
|
|
47
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
48
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
49
|
+
/** 接口调用失败的回调函数 */
|
|
50
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
51
|
+
/** 接口调用成功的回调函数 */
|
|
52
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
namespace getAvailableAudioSources {
|
|
57
|
+
interface Option {
|
|
58
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
59
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
60
|
+
/** 接口调用失败的回调函数 */
|
|
61
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
62
|
+
/** 接口调用成功的回调函数 */
|
|
63
|
+
success?: (result: SuccessCallbackResult) => void
|
|
64
|
+
}
|
|
65
|
+
interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
|
|
66
|
+
/** 支持的音频输入源列表,可在 [RecorderManager.start()](/docs/apis/media/recorder/RecorderManager#start)用。返回值定义参考 https://developer.android.com/reference/kotlin/android/media/MediaRecorder.AudioSource */
|
|
67
|
+
audioSources: Array<keyof audioSources>
|
|
68
|
+
/** 调用结果 */
|
|
69
|
+
errMsg: string
|
|
70
|
+
}
|
|
71
|
+
/** 支持的音频输入源 */
|
|
72
|
+
interface audioSources {
|
|
73
|
+
/** 自动设置,默认使用手机麦克风,插上耳麦后自动切换使用耳机麦克风,所有平台适用 */
|
|
74
|
+
'auto'
|
|
75
|
+
/** 手机麦克风,仅限 iOS */
|
|
76
|
+
'buildInMic'
|
|
77
|
+
/** 耳机麦克风,仅限 iOS */
|
|
78
|
+
'headsetMic'
|
|
79
|
+
/** 麦克风(没插耳麦时是手机麦克风,插耳麦时是耳机麦克风),仅限 Android */
|
|
80
|
+
'mic'
|
|
81
|
+
/** 同 mic,适用于录制音视频内容,仅限 Android */
|
|
82
|
+
'camcorder'
|
|
83
|
+
/** 同 mic,适用于实时沟通,仅限 Android */
|
|
84
|
+
'voice_communication'
|
|
85
|
+
/** 同 mic,适用于语音识别,仅限 Android */
|
|
86
|
+
'voice_recognition'
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** AudioBuffer 接口表示存在内存里的一段短小的音频资源,利用 [WebAudioContext.decodeAudioData](./WebAudioContext#decodeaudiodata) 方法从一个音频文件构建,或者利用 [AudioContext.createBuffer](https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/(AudioContext.createBuffer).html) 从原始数据构建。把音频放入 AudioBuffer 后,可以传入到一个 AudioBufferSourceNode 进行播放。
|
|
91
|
+
* @supported weapp
|
|
92
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/AudioBuffer.html
|
|
93
|
+
*/
|
|
94
|
+
interface AudioBuffer {
|
|
95
|
+
/** 存储在缓存区的PCM数据的采样率(单位为sample/s) */
|
|
96
|
+
sampleRate: number
|
|
97
|
+
|
|
98
|
+
/** 返回存储在缓存区的PCM数据的采样帧率 */
|
|
99
|
+
length: number
|
|
100
|
+
|
|
101
|
+
/** 返回存储在缓存区的PCM数据的时长(单位为秒) */
|
|
102
|
+
duration: number
|
|
103
|
+
|
|
104
|
+
/** 储存在缓存区的PCM数据的通道数 */
|
|
105
|
+
numberOfChannels: number
|
|
106
|
+
|
|
107
|
+
/** 返回一个 Float32Array,包含了带有频道的PCM数据,由频道参数定义(有0代表第一个频道)
|
|
108
|
+
* @supported weapp
|
|
109
|
+
* @example
|
|
110
|
+
* ```tsx
|
|
111
|
+
* const audioCtx = Taro.createWebAudioContext()
|
|
112
|
+
* const myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate);
|
|
113
|
+
* const nowBuffering = myArrayBuffer.getChannelData(channel);
|
|
114
|
+
* ```
|
|
115
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/AudioBuffer.getChannelData.html
|
|
116
|
+
*/
|
|
117
|
+
getChannelData(channel: number): Float32Array
|
|
118
|
+
|
|
119
|
+
/** 从 AudioBuffer 的指定频道复制到数组终端。
|
|
120
|
+
* @supported weapp
|
|
121
|
+
* @example
|
|
122
|
+
* ```tsx
|
|
123
|
+
* const audioCtx = Taro.createWebAudioContext()
|
|
124
|
+
* const audioBuffer = audioCtx.createFromAudioFile({
|
|
125
|
+
* filePath:'/pages/res/bgm.mp3', // 静态资源
|
|
126
|
+
* mixToMono:true,
|
|
127
|
+
* sampleRate:44100
|
|
128
|
+
* });
|
|
129
|
+
* const channels = audioBuffer.numberOfChannels
|
|
130
|
+
* const anotherArray = new Float32Array(frameCount);
|
|
131
|
+
* const rate = audioBuffer.sampleRate
|
|
132
|
+
* const startOffSet = 0
|
|
133
|
+
* const endOffset = rate * 3;
|
|
134
|
+
* const newAudioBuffer = audioCtx.createBuffer(channels,endOffset - startOffset,rate)
|
|
135
|
+
* const offset = 0
|
|
136
|
+
*
|
|
137
|
+
* for (let channel = 0; channel < channels; channel++) {
|
|
138
|
+
* audioBuffer.copyFromChannel(anotherArray, channel, startOffset);
|
|
139
|
+
* newAudioBuffer.copyToChannel(anotherArray, channel, offset);
|
|
140
|
+
* }
|
|
141
|
+
* ```
|
|
142
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/AudioBuffer.copyFromChannel.html
|
|
143
|
+
*/
|
|
144
|
+
copyFromChannel(): void
|
|
145
|
+
|
|
146
|
+
/** 从指定数组复制样本到 audioBuffer 的特定通道
|
|
147
|
+
* @supported weapp
|
|
148
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/AudioBuffer.copyToChannel.html
|
|
149
|
+
*/
|
|
150
|
+
copyToChannel(
|
|
151
|
+
/** 需要复制的源数组 */
|
|
152
|
+
source: Float32Array,
|
|
153
|
+
/** 需要复制到的目的通道号 */
|
|
154
|
+
channelNumber: number,
|
|
155
|
+
/** 复制偏移数据量 */
|
|
156
|
+
startInChannel: number
|
|
157
|
+
): void
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** `AudioContext` 实例,可通过 `Taro.createAudioContext` 获取。
|
|
161
|
+
*
|
|
162
|
+
* `AudioContext` 通过 `id` 跟一个 `audio` 组件绑定,操作对应的 audio 组件。
|
|
163
|
+
* @supported weapp, harmony_hybrid
|
|
164
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/AudioContext.html
|
|
165
|
+
*/
|
|
166
|
+
interface AudioContext {
|
|
167
|
+
/** 暂停音频。
|
|
168
|
+
* @supported weapp, harmony_hybrid
|
|
169
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/AudioContext.pause.html
|
|
170
|
+
*/
|
|
171
|
+
pause(): void
|
|
172
|
+
/** 播放音频。
|
|
173
|
+
* @supported weapp, harmony_hybrid
|
|
174
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/AudioContext.play.html
|
|
175
|
+
*/
|
|
176
|
+
play(): void
|
|
177
|
+
/** 跳转到指定位置。
|
|
178
|
+
* @supported weapp
|
|
179
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/AudioContext.seek.html
|
|
180
|
+
*/
|
|
181
|
+
seek(
|
|
182
|
+
/** 跳转位置,单位 s */
|
|
183
|
+
position: number,
|
|
184
|
+
): void
|
|
185
|
+
/** 设置音频地址
|
|
186
|
+
* @supported weapp
|
|
187
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/AudioContext.setSrc.html
|
|
188
|
+
*/
|
|
189
|
+
setSrc(
|
|
190
|
+
/** 音频地址 */
|
|
191
|
+
src: string,
|
|
192
|
+
): void
|
|
193
|
+
}
|
|
194
|
+
/** InnerAudioContext 实例,可通过 [Taro.createInnerAudioContext](./createInnerAudioContext) 接口获取实例。
|
|
195
|
+
*
|
|
196
|
+
* **支持格式**
|
|
197
|
+
*
|
|
198
|
+
* | 格式 | iOS | Android |
|
|
199
|
+
* | ---- | ---- | ------- |
|
|
200
|
+
* | flac | x | √ |
|
|
201
|
+
* | m4a | √ | √ |
|
|
202
|
+
* | ogg | x | √ |
|
|
203
|
+
* | ape | x | √ |
|
|
204
|
+
* | amr | x | √ |
|
|
205
|
+
* | wma | x | √ |
|
|
206
|
+
* | wav | √ | √ |
|
|
207
|
+
* | mp3 | √ | √ |
|
|
208
|
+
* | mp4 | x | √ |
|
|
209
|
+
* | aac | √ | √ |
|
|
210
|
+
* | aiff | √ | x |
|
|
211
|
+
* | caf | √ | x |
|
|
212
|
+
* @example
|
|
213
|
+
* ```tsx
|
|
214
|
+
* const innerAudioContext = Taro.createInnerAudioContext()
|
|
215
|
+
* innerAudioContext.autoplay = true
|
|
216
|
+
* innerAudioContext.src = 'https://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46'
|
|
217
|
+
* innerAudioContext.onPlay(() => {
|
|
218
|
+
* console.log('开始播放')
|
|
219
|
+
* })
|
|
220
|
+
* innerAudioContext.onError((res) => {
|
|
221
|
+
* console.log(res.errMsg)
|
|
222
|
+
* console.log(res.errCode)
|
|
223
|
+
* })
|
|
224
|
+
* ```
|
|
225
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/InnerAudioContext.html
|
|
226
|
+
*/
|
|
227
|
+
interface InnerAudioContext {
|
|
228
|
+
/** 音频资源的地址,用于直接播放。 */
|
|
229
|
+
src: string
|
|
230
|
+
/** 开始播放的位置(单位:s)
|
|
231
|
+
* @default 0
|
|
232
|
+
*/
|
|
233
|
+
startTime: number
|
|
234
|
+
/** 是否自动开始播放
|
|
235
|
+
* @default false
|
|
236
|
+
*/
|
|
237
|
+
autoplay: boolean
|
|
238
|
+
/** 是否循环播放
|
|
239
|
+
* @default false
|
|
240
|
+
*/
|
|
241
|
+
loop: boolean
|
|
242
|
+
/** 是否遵循系统静音开关。当此参数为 `false` 时,即使用户打开了静音开关,也能继续发出声音。从 2.3.0 版本开始此参数不生效,使用 [Taro.setInnerAudioOption](/docs/apis/media/audio/setInnerAudioOption) 接口统一设置。
|
|
243
|
+
* @default true
|
|
244
|
+
*/
|
|
245
|
+
obeyMuteSwitch: boolean
|
|
246
|
+
/** 音量。范围 0~1。
|
|
247
|
+
* @default 1
|
|
248
|
+
*/
|
|
249
|
+
volume: number
|
|
250
|
+
/** 播放速度。范围 0.5-2.0。
|
|
251
|
+
* @default 1
|
|
252
|
+
*/
|
|
253
|
+
playbackRate: number
|
|
254
|
+
/** 当前音频的长度(单位 s)。只有在当前有合法的 src 时返回
|
|
255
|
+
* @readonly
|
|
256
|
+
*/
|
|
257
|
+
duration: number
|
|
258
|
+
/** 当前音频的播放位置(单位 s)。只有在当前有合法的 src 时返回,时间保留小数点后 6 位
|
|
259
|
+
* @readonly
|
|
260
|
+
*/
|
|
261
|
+
currentTime: number
|
|
262
|
+
/** 当前是是否暂停或停止状态
|
|
263
|
+
* @readonly
|
|
264
|
+
*/
|
|
265
|
+
paused: boolean
|
|
266
|
+
/** 音频缓冲的时间点,仅保证当前播放时间点到此时间点内容已缓冲
|
|
267
|
+
* @readonly
|
|
268
|
+
*/
|
|
269
|
+
buffered: number
|
|
270
|
+
/** origin: 发送完整的 referrer; no-referrer: 不发送 */
|
|
271
|
+
referrerPolicy?: 'origin' | 'no-referrer' | string
|
|
272
|
+
/** 播放
|
|
273
|
+
* @supported weapp, h5, rn, harmony_hybrid
|
|
274
|
+
*/
|
|
275
|
+
play(): void
|
|
276
|
+
/** 暂停
|
|
277
|
+
* @supported weapp, h5, rn
|
|
278
|
+
*/
|
|
279
|
+
pause(): void
|
|
280
|
+
/** 停止
|
|
281
|
+
* @supported weapp, h5, rn, harmony_hybrid
|
|
282
|
+
*/
|
|
283
|
+
stop(): void
|
|
284
|
+
/** 跳转到指定位置,单位 s
|
|
285
|
+
* @supported weapp, h5, rn
|
|
286
|
+
*/
|
|
287
|
+
seek(position: number): void
|
|
288
|
+
/** 销毁当前实例
|
|
289
|
+
* @supported weapp, h5
|
|
290
|
+
*/
|
|
291
|
+
destroy(): void
|
|
292
|
+
/** 音频进入可以播放状态,但不保证后面可以流畅播放
|
|
293
|
+
* @supported weapp, h5, rn
|
|
294
|
+
*/
|
|
295
|
+
onCanplay(callback?: InnerAudioContext.OnCanplayCallback): void
|
|
296
|
+
/** 音频播放事件
|
|
297
|
+
* @supported weapp, h5, rn, harmony_hybrid
|
|
298
|
+
*/
|
|
299
|
+
onPlay(callback?: InnerAudioContext.OnPlayCallback): void
|
|
300
|
+
/** 音频暂停事件
|
|
301
|
+
* @supported weapp, h5, rn
|
|
302
|
+
*/
|
|
303
|
+
onPause(callback?: InnerAudioContext.OnPauseCallback): void
|
|
304
|
+
/** 音频停止事件
|
|
305
|
+
* @supported weapp, h5, rn, harmony_hybrid
|
|
306
|
+
*/
|
|
307
|
+
onStop(callback?: InnerAudioContext.OnStopCallback): void
|
|
308
|
+
/** 音频自然播放结束事件
|
|
309
|
+
* @supported weapp, h5, rn, harmony_hybrid
|
|
310
|
+
*/
|
|
311
|
+
onEnded(callback?: InnerAudioContext.OnEndedCallback): void
|
|
312
|
+
/** 音频播放进度更新事件
|
|
313
|
+
* @supported weapp, h5, rn
|
|
314
|
+
*/
|
|
315
|
+
onTimeUpdate(callback?: InnerAudioContext.OnTimeUpdateCallback): void
|
|
316
|
+
/** 音频播放错误事件
|
|
317
|
+
* @supported weapp, h5, rn, harmony_hybrid
|
|
318
|
+
*/
|
|
319
|
+
onError(callback?: InnerAudioContext.OnErrorCallback): void
|
|
320
|
+
/** 音频加载中事件,当音频因为数据不足,需要停下来加载时会触发
|
|
321
|
+
* @supported weapp, h5, rn
|
|
322
|
+
*/
|
|
323
|
+
onWaiting(callback?: InnerAudioContext.OnWaitingCallback): void
|
|
324
|
+
/** 音频进行 seek 操作事件
|
|
325
|
+
* @supported weapp, h5, rn
|
|
326
|
+
*/
|
|
327
|
+
onSeeking(callback?: InnerAudioContext.OnSeekingCallback): void
|
|
328
|
+
/** 音频完成 seek 操作事件
|
|
329
|
+
* @supported weapp, h5, rn
|
|
330
|
+
*/
|
|
331
|
+
onSeeked(callback?: InnerAudioContext.OnSeekedCallback): void
|
|
332
|
+
/** 取消监听 canplay 事件
|
|
333
|
+
* @supported weapp, h5, rn
|
|
334
|
+
*/
|
|
335
|
+
offCanplay(callback?: InnerAudioContext.OnCanplayCallback): void
|
|
336
|
+
/** 取消监听 play 事件
|
|
337
|
+
* @supported weapp, h5, rn
|
|
338
|
+
*/
|
|
339
|
+
offPlay(callback?: InnerAudioContext.OnPlayCallback): void
|
|
340
|
+
/** 取消监听 pause 事件
|
|
341
|
+
* @supported weapp, h5, rn
|
|
342
|
+
*/
|
|
343
|
+
offPause(callback?: InnerAudioContext.OnPauseCallback): void
|
|
344
|
+
/** 取消监听 stop 事件
|
|
345
|
+
* @supported weapp, h5, rn
|
|
346
|
+
*/
|
|
347
|
+
offStop(callback?: InnerAudioContext.OnStopCallback): void
|
|
348
|
+
/** 取消监听 ended 事件
|
|
349
|
+
* @supported weapp, h5, rn
|
|
350
|
+
*/
|
|
351
|
+
offEnded(callback?: InnerAudioContext.OnEndedCallback): void
|
|
352
|
+
/** 取消监听 timeUpdate 事件
|
|
353
|
+
* @supported weapp, h5, rn
|
|
354
|
+
*/
|
|
355
|
+
offTimeUpdate(callback?: InnerAudioContext.OnTimeUpdateCallback): void
|
|
356
|
+
/** 取消监听 error 事件
|
|
357
|
+
* @supported weapp, h5, rn
|
|
358
|
+
*/
|
|
359
|
+
offError(callback?: InnerAudioContext.OnErrorCallback): void
|
|
360
|
+
/** 取消监听 waiting 事件
|
|
361
|
+
* @supported weapp, h5, rn
|
|
362
|
+
*/
|
|
363
|
+
offWaiting(callback?: InnerAudioContext.OnWaitingCallback): void
|
|
364
|
+
/** 取消监听 seeking 事件
|
|
365
|
+
* @supported weapp, h5, rn
|
|
366
|
+
*/
|
|
367
|
+
offSeeking(callback?: InnerAudioContext.OnSeekingCallback): void
|
|
368
|
+
/** 取消监听 seeked 事件
|
|
369
|
+
* @supported weapp, h5, rn
|
|
370
|
+
*/
|
|
371
|
+
offSeeked(callback?: InnerAudioContext.OnSeekedCallback): void
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
namespace InnerAudioContext {
|
|
375
|
+
interface onErrorDetail extends TaroGeneral.CallbackResult {
|
|
376
|
+
/** 错误码 */
|
|
377
|
+
errCode: number
|
|
378
|
+
/** 错误信息 */
|
|
379
|
+
errMsg: string
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
interface onErrorDetailErrCode {
|
|
383
|
+
/** 系统错误 */
|
|
384
|
+
10001
|
|
385
|
+
/** 网络错误 */
|
|
386
|
+
10002
|
|
387
|
+
/** 文件错误 */
|
|
388
|
+
10003
|
|
389
|
+
/** 格式错误 */
|
|
390
|
+
10004
|
|
391
|
+
/** 未知错误 */
|
|
392
|
+
'-1'
|
|
393
|
+
}
|
|
394
|
+
/** 音频进入可以播放状态事件的回调函数 */
|
|
395
|
+
type OnCanplayCallback = (res: Partial<TaroGeneral.CallbackResult>) => void
|
|
396
|
+
/** 音频播放事件的回调函数 */
|
|
397
|
+
type OnPlayCallback = (res: Partial<TaroGeneral.CallbackResult>) => void
|
|
398
|
+
/** 音频暂停事件的回调函数 */
|
|
399
|
+
type OnPauseCallback = (res: Partial<TaroGeneral.CallbackResult>) => void
|
|
400
|
+
/** 音频停止事件的回调函数 */
|
|
401
|
+
type OnStopCallback = (res: Partial<TaroGeneral.CallbackResult>) => void
|
|
402
|
+
/** 音频自然播放结束事件的回调函数 */
|
|
403
|
+
type OnEndedCallback = (res: Partial<TaroGeneral.CallbackResult>) => void
|
|
404
|
+
/** 音频播放进度更新事件的回调函数 */
|
|
405
|
+
type OnTimeUpdateCallback = (res: Partial<TaroGeneral.CallbackResult>) => void
|
|
406
|
+
/** 音频播放错误事件的回调函数 */
|
|
407
|
+
type OnErrorCallback = (res: onErrorDetail) => void
|
|
408
|
+
/** 音频加载中事件的回调函数 */
|
|
409
|
+
type OnWaitingCallback = (res: Partial<TaroGeneral.CallbackResult>) => void
|
|
410
|
+
/** 音频进行 seek 操作事件的回调函数 */
|
|
411
|
+
type OnSeekingCallback = (res: Partial<TaroGeneral.CallbackResult>) => void
|
|
412
|
+
/** 音频完成 seek 操作事件的回调函数 */
|
|
413
|
+
type OnSeekedCallback = (res: Partial<TaroGeneral.CallbackResult>) => void
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** MediaAudioPlayer 实例,可通过 [Taro.createMediaAudioPlayer](./createMediaAudioPlayer) 接口获取实例。
|
|
417
|
+
* @supported weapp
|
|
418
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/MediaAudioPlayer.html
|
|
419
|
+
*/
|
|
420
|
+
interface MediaAudioPlayer {
|
|
421
|
+
/** 音量。范围 0~1
|
|
422
|
+
* @default 1
|
|
423
|
+
*/
|
|
424
|
+
volume: number
|
|
425
|
+
|
|
426
|
+
/** 启动播放器
|
|
427
|
+
* @supported weapp
|
|
428
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/MediaAudioPlayer.start.html
|
|
429
|
+
*/
|
|
430
|
+
start(): Promise<void>
|
|
431
|
+
|
|
432
|
+
/** 添加音频源
|
|
433
|
+
* @supported weapp
|
|
434
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/MediaAudioPlayer.addAudioSource.html
|
|
435
|
+
*/
|
|
436
|
+
addAudioSource(
|
|
437
|
+
/** 视频解码器实例。作为音频源添加到音频播放器中 */
|
|
438
|
+
source: VideoDecoder
|
|
439
|
+
): Promise<void>
|
|
440
|
+
|
|
441
|
+
/** 移除音频源
|
|
442
|
+
* @supported weapp
|
|
443
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/MediaAudioPlayer.removeAudioSource.html
|
|
444
|
+
*/
|
|
445
|
+
removeAudioSource(
|
|
446
|
+
/** 视频解码器实例 */
|
|
447
|
+
source: VideoDecoder
|
|
448
|
+
): Promise<void>
|
|
449
|
+
|
|
450
|
+
/** 停止播放器
|
|
451
|
+
* @supported weapp
|
|
452
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/MediaAudioPlayer.stop.html
|
|
453
|
+
*/
|
|
454
|
+
stop(): Promise<void>
|
|
455
|
+
|
|
456
|
+
/** 销毁播放器
|
|
457
|
+
* @supported weapp
|
|
458
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/MediaAudioPlayer.destroy.html
|
|
459
|
+
*/
|
|
460
|
+
destroy(): Promise<void>
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/** WebAudioContext 实例,通过 [Taro.createWebAudioContext](./createWebAudioContext) 接口获取该实例。
|
|
464
|
+
* @supported weapp
|
|
465
|
+
* @example
|
|
466
|
+
* 监听状态
|
|
467
|
+
*
|
|
468
|
+
* ```tsx
|
|
469
|
+
* const audioCtx = Taro.createWebAudioContext()
|
|
470
|
+
* audioCtx.onstatechange = () => {
|
|
471
|
+
* console.log(ctx.state)
|
|
472
|
+
* }
|
|
473
|
+
* setTimeout(audioCtx.suspend, 1000)
|
|
474
|
+
* setTimeout(audioCtx.resume, 2000)
|
|
475
|
+
* ```
|
|
476
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.html
|
|
477
|
+
*/
|
|
478
|
+
interface WebAudioContext {
|
|
479
|
+
/** 当前 WebAudio 上下文的状态。
|
|
480
|
+
*
|
|
481
|
+
* 可能的值如下:suspended(暂停)、running(正在运行)、closed(已关闭)。
|
|
482
|
+
* 需要注意的是,不要在 audioContext close 后再访问 state 属性
|
|
483
|
+
*/
|
|
484
|
+
state: string
|
|
485
|
+
|
|
486
|
+
/** 可写属性,开发者可以对该属性设置一个监听函数,当 WebAudio 状态改变的时候,会触发开发者设置的监听函数。 */
|
|
487
|
+
onstatechange: () => void
|
|
488
|
+
|
|
489
|
+
/** 获取当前上下文的时间戳。 */
|
|
490
|
+
currentTime: number
|
|
491
|
+
|
|
492
|
+
/** 当前上下文的最终目标节点,一般是音频渲染设备。 */
|
|
493
|
+
destination: WebAudioContextNode
|
|
494
|
+
|
|
495
|
+
/** 空间音频监听器。 */
|
|
496
|
+
listener: AudioListener
|
|
497
|
+
|
|
498
|
+
/** 采样率,通常在 8000-96000 之间,通常 44100hz 的采样率最为常见。 */
|
|
499
|
+
sampleRate: number
|
|
500
|
+
|
|
501
|
+
/** 关闭WebAudioContext
|
|
502
|
+
*
|
|
503
|
+
* **注意事项**
|
|
504
|
+
* 同步关闭对应的 WebAudio 上下文。close 后会立即释放当前上下文的资源,**不要在 close 后再次访问 state 属性**。
|
|
505
|
+
* @supported weapp
|
|
506
|
+
* @example
|
|
507
|
+
* ```tsx
|
|
508
|
+
* const audioCtx = Taro.createWebAudioContext()
|
|
509
|
+
* audioCtx.close().then(() => {
|
|
510
|
+
* console.log(audioCtx.state) // bad case:不应该在close后再访问state
|
|
511
|
+
* })
|
|
512
|
+
* ```
|
|
513
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.close.html
|
|
514
|
+
*/
|
|
515
|
+
close(): Promise<void>
|
|
516
|
+
|
|
517
|
+
/** 同步恢复已经被暂停的 WebAudioContext 上下文
|
|
518
|
+
* @supported weapp
|
|
519
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.resume.html
|
|
520
|
+
*/
|
|
521
|
+
resume(): Promise<void>
|
|
522
|
+
|
|
523
|
+
/** 同步暂停 WebAudioContext 上下文
|
|
524
|
+
* @supported weapp
|
|
525
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.suspend.html
|
|
526
|
+
*/
|
|
527
|
+
suspend(): Promise<void>
|
|
528
|
+
|
|
529
|
+
/** 创建一个 IIRFilterNode
|
|
530
|
+
* @supported weapp
|
|
531
|
+
* @example
|
|
532
|
+
* ```tsx
|
|
533
|
+
* let lowPassCoefs = [
|
|
534
|
+
* {
|
|
535
|
+
* frequency: 200,
|
|
536
|
+
* feedforward: [0.00020298, 0.0004059599, 0.00020298],
|
|
537
|
+
* feedback: [1.0126964558, -1.9991880801, 0.9873035442]
|
|
538
|
+
* },
|
|
539
|
+
* {
|
|
540
|
+
* frequency: 500,
|
|
541
|
+
* feedforward: [0.0012681742, 0.0025363483, 0.0012681742],
|
|
542
|
+
* feedback: [1.0317185917, -1.9949273033, 0.9682814083]
|
|
543
|
+
* },
|
|
544
|
+
* {
|
|
545
|
+
* frequency: 1000,
|
|
546
|
+
* feedforward: [0.0050662636, 0.0101325272, 0.0050662636],
|
|
547
|
+
* feedback: [1.0632762845, -1.9797349456, 0.9367237155]
|
|
548
|
+
* },
|
|
549
|
+
* {
|
|
550
|
+
* frequency: 5000,
|
|
551
|
+
* feedforward: [0.1215955842, 0.2431911684, 0.1215955842],
|
|
552
|
+
* feedback: [1.2912769759, -1.5136176632, 0.7087230241]
|
|
553
|
+
* }
|
|
554
|
+
* ]
|
|
555
|
+
*
|
|
556
|
+
* const feedForward = lowPassCoefs[filterNumber].feedforward
|
|
557
|
+
* const feedBack = lowPassCoefs[filterNumber].feedback
|
|
558
|
+
* const iirFilter = audioContext.createIIRFilter(feedForward, feedBack)
|
|
559
|
+
* ```
|
|
560
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.createIIRFilter.html
|
|
561
|
+
*/
|
|
562
|
+
createIIRFilter(
|
|
563
|
+
/** 一个浮点值数组,指定IIR滤波器传递函数的前馈(分子)系数。 */
|
|
564
|
+
feedforward: number[],
|
|
565
|
+
/** 一个浮点值数组,指定IIR滤波器传递函数的反馈(分母)系数。 */
|
|
566
|
+
feedback: number[]
|
|
567
|
+
): IIRFilterNode
|
|
568
|
+
|
|
569
|
+
/** 创建一个 WaveShaperNode
|
|
570
|
+
* @supported weapp
|
|
571
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.createWaveShaper.html
|
|
572
|
+
*/
|
|
573
|
+
createWaveShaper(): WaveShaperNode
|
|
574
|
+
|
|
575
|
+
/** 创建一个 ConstantSourceNode
|
|
576
|
+
* @supported weapp
|
|
577
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.createConstantSource.html
|
|
578
|
+
*/
|
|
579
|
+
createConstantSource(): ConstantSourceNode
|
|
580
|
+
|
|
581
|
+
/** 创建一个 OscillatorNode
|
|
582
|
+
* @supported weapp
|
|
583
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.createOscillator.html
|
|
584
|
+
*/
|
|
585
|
+
createOscillator(): OscillatorNode
|
|
586
|
+
|
|
587
|
+
/** 创建一个 GainNode
|
|
588
|
+
* @supported weapp
|
|
589
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.createGain.html
|
|
590
|
+
*/
|
|
591
|
+
createGain(): GainNode
|
|
592
|
+
|
|
593
|
+
/** 创建一个 PeriodicWaveNode
|
|
594
|
+
*
|
|
595
|
+
* **注意**
|
|
596
|
+
* `real` 和 `imag` 数组必须拥有一样的长度,否则抛出错误
|
|
597
|
+
*
|
|
598
|
+
* ```tsx
|
|
599
|
+
* const real = new Float32Array(2)
|
|
600
|
+
* const imag = new Float32Array(2)
|
|
601
|
+
* real[0] = 0
|
|
602
|
+
* imag[0] = 0
|
|
603
|
+
* real[1] = 1
|
|
604
|
+
* imag[1] = 0
|
|
605
|
+
*
|
|
606
|
+
* const waveNode = audioContext.createPeriodicWave(real, imag, {disableNormalization: true})
|
|
607
|
+
* ```
|
|
608
|
+
* @supported weapp
|
|
609
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.createPeriodicWave.html
|
|
610
|
+
*/
|
|
611
|
+
createPeriodicWave(
|
|
612
|
+
/** 一组余弦项(传统上是A项) */
|
|
613
|
+
real: Float32Array,
|
|
614
|
+
/** 一组余弦项(传统上是A项) */
|
|
615
|
+
imag: Float32Array,
|
|
616
|
+
/** 一个字典对象,它指定是否应该禁用规范化(默认启用规范化) */
|
|
617
|
+
constraints: WebAudioContext.createPeriodicWave.Constraints
|
|
618
|
+
): PeriodicWave
|
|
619
|
+
|
|
620
|
+
/** 创建一个BiquadFilterNode
|
|
621
|
+
* @supported weapp
|
|
622
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.createBiquadFilter.html
|
|
623
|
+
*/
|
|
624
|
+
createBiquadFilter(): BiquadFilterNode
|
|
625
|
+
|
|
626
|
+
/** 创建一个 BufferSourceNode 实例,通过 AudioBuffer 对象来播放音频数据。
|
|
627
|
+
* @supported weapp
|
|
628
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.createBufferSource.html
|
|
629
|
+
*/
|
|
630
|
+
createBufferSource(): AudioBufferSourceNode
|
|
631
|
+
|
|
632
|
+
/** 创建一个ChannelMergerNode
|
|
633
|
+
* @supported weapp
|
|
634
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.createChannelMerger.html
|
|
635
|
+
*/
|
|
636
|
+
createChannelMerger(
|
|
637
|
+
/** 输出流中需要保持的输入流的个数 */
|
|
638
|
+
numberOfInputs: number
|
|
639
|
+
): ChannelMergerNode
|
|
640
|
+
|
|
641
|
+
/** 创建一个ChannelSplitterNode
|
|
642
|
+
* @supported weapp
|
|
643
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.createChannelSplitter.html
|
|
644
|
+
*/
|
|
645
|
+
createChannelSplitter(
|
|
646
|
+
/** 要分别输出的输入音频流中的通道数 */
|
|
647
|
+
numberOfOutputs: number
|
|
648
|
+
): ChannelSplitterNode
|
|
649
|
+
|
|
650
|
+
/** 创建一个DelayNode
|
|
651
|
+
* @supported weapp
|
|
652
|
+
* @example
|
|
653
|
+
* ```tsx
|
|
654
|
+
* let audioCtx = Taro.createWebAudioContext()
|
|
655
|
+
* const delayNode = audioCtx.createDelay(5)
|
|
656
|
+
* ```
|
|
657
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.createDelay.html
|
|
658
|
+
*/
|
|
659
|
+
createDelay(
|
|
660
|
+
/** 最大延迟时间 */
|
|
661
|
+
maxDelayTime: number
|
|
662
|
+
): DelayNode
|
|
663
|
+
|
|
664
|
+
/** 创建一个DynamicsCompressorNode
|
|
665
|
+
* @supported weapp
|
|
666
|
+
* @example
|
|
667
|
+
* ```tsx
|
|
668
|
+
* let audioCtx = Taro.createWebAudioContext()
|
|
669
|
+
* let compressor = audioCtx.createDynamicsCompressor()
|
|
670
|
+
*
|
|
671
|
+
* compressor.threshold.value = -50
|
|
672
|
+
* compressor.knee.value = 40
|
|
673
|
+
* compressor.ratio.value = 12
|
|
674
|
+
* compressor.attack.value = 0
|
|
675
|
+
* compressor.release.value = 0.25
|
|
676
|
+
* ```
|
|
677
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.createDynamicsCompressor.html
|
|
678
|
+
*/
|
|
679
|
+
createDynamicsCompressor(): DynamicsCompressorNode
|
|
680
|
+
|
|
681
|
+
/** 创建一个ScriptProcessorNode
|
|
682
|
+
* @supported weapp
|
|
683
|
+
* @example
|
|
684
|
+
* ```tsx
|
|
685
|
+
* let audioCtx = Taro.createWebAudioContext()
|
|
686
|
+
* const sampleSize = 4096
|
|
687
|
+
* audioContext.createScriptProcessor(sampleSize, 1, 1)
|
|
688
|
+
* ```
|
|
689
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.createScriptProcessor.html
|
|
690
|
+
*/
|
|
691
|
+
createScriptProcessor(
|
|
692
|
+
/** 缓冲区大小,以样本帧为单位 */
|
|
693
|
+
bufferSize: number,
|
|
694
|
+
/** 用于指定输入 node 的声道的数量 */
|
|
695
|
+
numberOfInputChannels: number,
|
|
696
|
+
/** 用于指定输出 node 的声道的数量 */
|
|
697
|
+
numberOfOutputChannels: number
|
|
698
|
+
): ScriptProcessorNode
|
|
699
|
+
|
|
700
|
+
/** 创建一个PannerNode
|
|
701
|
+
* @supported weapp
|
|
702
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.createPanner.html
|
|
703
|
+
*/
|
|
704
|
+
createPanner(): PannerNode
|
|
705
|
+
|
|
706
|
+
/** 创建一个AudioBuffer,代表着一段驻留在内存中的短音频
|
|
707
|
+
* @supported weapp
|
|
708
|
+
* @example
|
|
709
|
+
* ```tsx
|
|
710
|
+
* const audioCtx = Taro.createWebAudioContext()
|
|
711
|
+
* const channels = 2, frameCount = audioCtx.sampleRate * 2.0
|
|
712
|
+
* const myArrayBuffer = audioCtx.createBuffer(channels, frameCount, audioCtx.sampleRate)
|
|
713
|
+
* ```
|
|
714
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.createBuffer.html
|
|
715
|
+
*/
|
|
716
|
+
createBuffer(
|
|
717
|
+
/** 定义了 buffer 中包含的声频通道数量的整数 */
|
|
718
|
+
numOfChannels: number,
|
|
719
|
+
/** 代表 buffer 中的样本帧数的整数 */
|
|
720
|
+
length: number,
|
|
721
|
+
/** 线性音频样本的采样率,即每一秒包含的关键帧的个数 */
|
|
722
|
+
sampleRate: number
|
|
723
|
+
): AudioBuffer
|
|
724
|
+
|
|
725
|
+
/** 异步解码一段资源为AudioBuffer。
|
|
726
|
+
* @supported weapp
|
|
727
|
+
* @example
|
|
728
|
+
* ```tsx
|
|
729
|
+
* Taro.request({
|
|
730
|
+
* url: url, // 音频 url
|
|
731
|
+
* responseType: 'arraybuffer',
|
|
732
|
+
* success: res => {
|
|
733
|
+
* audioCtx.decodeAudioData(res.data, buffer => {
|
|
734
|
+
* console.log(buffer)
|
|
735
|
+
* }, err => {
|
|
736
|
+
* console.error('decodeAudioData fail', err)
|
|
737
|
+
* })
|
|
738
|
+
* }
|
|
739
|
+
* })
|
|
740
|
+
* ```
|
|
741
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.decodeAudioData.html
|
|
742
|
+
*/
|
|
743
|
+
decodeAudioData(
|
|
744
|
+
audioData: ArrayBuffer,
|
|
745
|
+
successCallback: (buffer: AudioBuffer) => void,
|
|
746
|
+
errorCallback: (error: any) => void
|
|
747
|
+
): Promise<AudioBuffer>
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
namespace WebAudioContext {
|
|
751
|
+
namespace createPeriodicWave {
|
|
752
|
+
/** 字典对象 */
|
|
753
|
+
interface Constraints {
|
|
754
|
+
/** 如果指定为 true 则禁用标准化
|
|
755
|
+
* @default false
|
|
756
|
+
*/
|
|
757
|
+
disableNormalization?: boolean
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
/** 一类音频处理模块,不同的Node具备不同的功能,如GainNode(音量调整)等。一个 WebAudioContextNode 可以通过上下文来创建。
|
|
763
|
+
*
|
|
764
|
+
* > 目前已经支持以下Node: IIRFilterNode WaveShaperNode ConstantSourceNode ChannelMergerNode OscillatorNode GainNode BiquadFilterNode PeriodicWaveNode BufferSourceNode ChannelSplitterNode ChannelMergerNode DelayNode DynamicsCompressorNode ScriptProcessorNode PannerNode
|
|
765
|
+
* @supported weapp
|
|
766
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContextNode.html
|
|
767
|
+
*/
|
|
768
|
+
interface WebAudioContextNode {
|
|
769
|
+
/** 右手笛卡尔坐标系中X轴的位置。 */
|
|
770
|
+
positionX: number
|
|
771
|
+
|
|
772
|
+
/** 右手笛卡尔坐标系中Y轴的位置。 */
|
|
773
|
+
positionY: number
|
|
774
|
+
|
|
775
|
+
/** 右手笛卡尔坐标系中Z轴的位置。 */
|
|
776
|
+
positionZ: number
|
|
777
|
+
|
|
778
|
+
/** 表示监听器的前向系统在同一笛卡尔坐标系中的水平位置,作为位置(位置x,位置和位置和位置)值。 */
|
|
779
|
+
forwardX: number
|
|
780
|
+
|
|
781
|
+
/** 表示听众的前向方向在同一笛卡尔坐标系中作为位置(位置x,位置和位置和位置)值的垂直位置。 */
|
|
782
|
+
forwardY: number
|
|
783
|
+
|
|
784
|
+
/** 表示与position (positionX、positionY和positionZ)值在同一笛卡尔坐标系下的听者前进方向的纵向(前后)位置。 */
|
|
785
|
+
forwardZ: number
|
|
786
|
+
|
|
787
|
+
/** 表示在与position (positionX、positionY和positionZ)值相同的笛卡尔坐标系中侦听器向前方向的水平位置。 */
|
|
788
|
+
upX: number
|
|
789
|
+
|
|
790
|
+
/** 表示在与position (positionX、positionY和positionZ)值相同的笛卡尔坐标系中侦听器向上方向的水平位置。 */
|
|
791
|
+
upY: number
|
|
792
|
+
|
|
793
|
+
/** 表示在与position (positionX、positionY和positionZ)值相同的笛卡尔坐标系中侦听器向后方向的水平位置。 */
|
|
794
|
+
upZ: number
|
|
795
|
+
|
|
796
|
+
/** 设置监听器的方向
|
|
797
|
+
* @supported weapp
|
|
798
|
+
*/
|
|
799
|
+
setOrientation(...args: any[]): void
|
|
800
|
+
|
|
801
|
+
/** 设置监听器的位置
|
|
802
|
+
* @supported weapp
|
|
803
|
+
*/
|
|
804
|
+
setPosition(...args: any[]): void
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
namespace createInnerAudioContext {
|
|
808
|
+
interface Option {
|
|
809
|
+
/** 是否使用 WebAudio 作为底层音频驱动,默认关闭。对于短音频、播放频繁的音频建议开启此选项,开启后将获得更优的性能表现。由于开启此选项后也会带来一定的内存增长,因此对于长音频建议关闭此选项。
|
|
810
|
+
* @supported weapp
|
|
811
|
+
*/
|
|
812
|
+
useWebAudioImplement: boolean
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
interface TaroStatic {
|
|
817
|
+
/** 结束播放语音。
|
|
818
|
+
* **注意:1.6.0 版本开始,本接口不再维护。建议使用能力更强的 [Taro.createInnerAudioContext](./createInnerAudioContext) 接口**
|
|
819
|
+
* @supported weapp
|
|
820
|
+
* @example
|
|
821
|
+
* ```tsx
|
|
822
|
+
* Taro.startRecord({
|
|
823
|
+
* success: function (res) {
|
|
824
|
+
* const filePath = res.tempFilePath
|
|
825
|
+
* Taro.playVoice({ filePath })
|
|
826
|
+
*
|
|
827
|
+
* setTimeout(Taro.stopVoice, 5000)
|
|
828
|
+
* }
|
|
829
|
+
* })
|
|
830
|
+
* ```
|
|
831
|
+
* @example
|
|
832
|
+
* ```tsx
|
|
833
|
+
* Taro.startRecord(params).then(res => {
|
|
834
|
+
* const filePath = res.tempFilePath
|
|
835
|
+
* Taro.playVoice({ filePath })
|
|
836
|
+
*
|
|
837
|
+
* setTimeout(Taro.stopVoice, 5000)
|
|
838
|
+
* })
|
|
839
|
+
* ```
|
|
840
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/wx.stopVoice.html
|
|
841
|
+
*/
|
|
842
|
+
stopVoice(option?: stopVoice.Option): void
|
|
843
|
+
|
|
844
|
+
/** 设置 [InnerAudioContext](/docs/apis/media/audio/InnerAudioContext)项。设置之后对当前小程序全局生效。
|
|
845
|
+
* @supported weapp
|
|
846
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/wx.setInnerAudioOption.html
|
|
847
|
+
*/
|
|
848
|
+
setInnerAudioOption(option: setInnerAudioOption.Option): Promise<TaroGeneral.CallbackResult>
|
|
849
|
+
|
|
850
|
+
/** 开始播放语音。同时只允许一个语音文件正在播放,如果前一个语音文件还没播放完,将中断前一个语音播放。
|
|
851
|
+
* @supported weapp
|
|
852
|
+
* @example
|
|
853
|
+
* ```tsx
|
|
854
|
+
* Taro.startRecord({
|
|
855
|
+
* success: function (res) {
|
|
856
|
+
* const tempFilePath = res.tempFilePath
|
|
857
|
+
* Taro.playVoice({
|
|
858
|
+
* filePath: tempFilePath,
|
|
859
|
+
* complete: function () { }
|
|
860
|
+
* })
|
|
861
|
+
* }
|
|
862
|
+
* })
|
|
863
|
+
* ```
|
|
864
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/wx.playVoice.html
|
|
865
|
+
*/
|
|
866
|
+
playVoice(option: playVoice.Option): Promise<TaroGeneral.CallbackResult>
|
|
867
|
+
|
|
868
|
+
/** 暂停正在播放的语音。再次调用 [Taro.playVoice](/docs/apis/media/audio/stopVoice)。
|
|
869
|
+
* **注意:1.6.0 版本开始,本接口不再维护。建议使用能力更强的 [Taro.createInnerAudioContext](./createInnerAudioContext) 接口**
|
|
870
|
+
* @supported weapp
|
|
871
|
+
* @example
|
|
872
|
+
* ```tsx
|
|
873
|
+
* Taro.startRecord({
|
|
874
|
+
* success: function (res) {
|
|
875
|
+
* var tempFilePath = res.tempFilePath
|
|
876
|
+
* Taro.playVoice({
|
|
877
|
+
* filePath: tempFilePath
|
|
878
|
+
* })
|
|
879
|
+
* setTimeout(function() {
|
|
880
|
+
* //暂停播放
|
|
881
|
+
* Taro.pauseVoice()
|
|
882
|
+
* }, 5000)
|
|
883
|
+
* }
|
|
884
|
+
* })
|
|
885
|
+
* ```
|
|
886
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/wx.pauseVoice.html
|
|
887
|
+
*/
|
|
888
|
+
pauseVoice(option?: pauseVoice.Option): void
|
|
889
|
+
|
|
890
|
+
/** 获取当前支持的音频输入源
|
|
891
|
+
* @supported weapp
|
|
892
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/wx.getAvailableAudioSources.html
|
|
893
|
+
*/
|
|
894
|
+
getAvailableAudioSources(option?: getAvailableAudioSources.Option): Promise<getAvailableAudioSources.SuccessCallbackResult>
|
|
895
|
+
|
|
896
|
+
/** 创建 WebAudio 上下文。
|
|
897
|
+
* @supported weapp
|
|
898
|
+
* @example
|
|
899
|
+
* 一个简单的播放demo
|
|
900
|
+
*
|
|
901
|
+
* ```tsx
|
|
902
|
+
* const audioCtx = Taro.createWebAudioContext()
|
|
903
|
+
*
|
|
904
|
+
* const loadAudio = (url) => {
|
|
905
|
+
* return new Promise((resolve) => {
|
|
906
|
+
* Taro.request({
|
|
907
|
+
* url,
|
|
908
|
+
* responseType: 'arraybuffer',
|
|
909
|
+
* success: res => {
|
|
910
|
+
* console.log('res.data', res.data)
|
|
911
|
+
* audioCtx.decodeAudioData(res.data, buffer => {
|
|
912
|
+
* resolve(buffer)
|
|
913
|
+
* }, err => {
|
|
914
|
+
* console.error('decodeAudioData fail', err)
|
|
915
|
+
* reject()
|
|
916
|
+
* })
|
|
917
|
+
* },
|
|
918
|
+
* fail: res => {
|
|
919
|
+
* console.error('request fail', res)
|
|
920
|
+
* reject()
|
|
921
|
+
* }
|
|
922
|
+
* })
|
|
923
|
+
* })
|
|
924
|
+
* }
|
|
925
|
+
*
|
|
926
|
+
* const play = () => {
|
|
927
|
+
* loadAudio('xxx-test.mp3').then(buffer => {
|
|
928
|
+
* const source = audioCtx.createBufferSource()
|
|
929
|
+
* source.buffer = buffer
|
|
930
|
+
* source.connect(audioCtx.destination)
|
|
931
|
+
* source.start()
|
|
932
|
+
* }).catch(() => {
|
|
933
|
+
* console.log('fail')
|
|
934
|
+
* })
|
|
935
|
+
* }
|
|
936
|
+
*
|
|
937
|
+
* play()
|
|
938
|
+
* ```
|
|
939
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/wx.createWebAudioContext.html
|
|
940
|
+
*/
|
|
941
|
+
createWebAudioContext(): WebAudioContext
|
|
942
|
+
|
|
943
|
+
/** 创建媒体音频播放器对象 [MediaAudioPlayer](./MediaAudioPlayer) 对象,可用于播放视频解码器 [VideoDecoder](/docs/apis/media/video-decoder/VideoDecoder) 输出的音频
|
|
944
|
+
*
|
|
945
|
+
* **注意事项**
|
|
946
|
+
* - iOS 7.0.15 mediaAudioPlayer 播放网络视频资源会出现音频卡顿,本地视频没有这个问题,将下一个客户端版本修复。
|
|
947
|
+
* @supported weapp
|
|
948
|
+
* @example
|
|
949
|
+
* ```tsx
|
|
950
|
+
* // 创建视频解码器,具体参数见 createVideoDecoder 文档
|
|
951
|
+
* const videoDecoder = Taro.createVideoDecoder()
|
|
952
|
+
* // 创建媒体音频播放器
|
|
953
|
+
* const mediaAudioPlayer = Taro.createMediaAudioPlayer()
|
|
954
|
+
* // 启动视频解码器
|
|
955
|
+
* videoDecoder.start()
|
|
956
|
+
* // 启动播放器
|
|
957
|
+
* mediaAudioPlayer.start().then(() => {
|
|
958
|
+
* // 添加播放器音频来源
|
|
959
|
+
* mediaAudioPlayer.addAudioSource(videoDecoder).then(res => {
|
|
960
|
+
* videoDecoder.getFrameData() // 建议在 requestAnimationFrame 里获取每一帧视频数据
|
|
961
|
+
* console.log(res)
|
|
962
|
+
* })
|
|
963
|
+
*
|
|
964
|
+
* // 移除播放器音频来源
|
|
965
|
+
* mediaAudioPlayer.removeAudioSource(videoDecoder).then()
|
|
966
|
+
* // 停止播放器
|
|
967
|
+
* mediaAudioPlayer.stop().then()
|
|
968
|
+
* // 销毁播放器
|
|
969
|
+
* mediaAudioPlayer.destroy().then()
|
|
970
|
+
* // 设置播放器音量
|
|
971
|
+
* mediaAudioPlayer.volume = 0.5
|
|
972
|
+
* })
|
|
973
|
+
*```
|
|
974
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/wx.createMediaAudioPlayer.html
|
|
975
|
+
*/
|
|
976
|
+
createMediaAudioPlayer(): MediaAudioPlayer
|
|
977
|
+
|
|
978
|
+
/** 创建内部 audio 上下文 InnerAudioContext 对象。
|
|
979
|
+
* @supported weapp, h5, rn, tt, harmony_hybrid
|
|
980
|
+
* @example
|
|
981
|
+
* ```tsx
|
|
982
|
+
* const innerAudioContext = Taro.createInnerAudioContext()
|
|
983
|
+
* innerAudioContext.autoplay = true
|
|
984
|
+
* innerAudioContext.src = 'https://storage.360buyimg.com/jdrd-blog/27.mp3'
|
|
985
|
+
* innerAudioContext.onPlay(() => {
|
|
986
|
+
* console.log('开始播放')
|
|
987
|
+
* })
|
|
988
|
+
* innerAudioContext.onError((res) => {
|
|
989
|
+
* console.log(res.errMsg)
|
|
990
|
+
* console.log(res.errCode)
|
|
991
|
+
* })
|
|
992
|
+
* ```
|
|
993
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/wx.createInnerAudioContext.html
|
|
994
|
+
*/
|
|
995
|
+
createInnerAudioContext(option?: createInnerAudioContext.Option): InnerAudioContext
|
|
996
|
+
|
|
997
|
+
/** 创建 audio 上下文 AudioContext 对象。
|
|
998
|
+
* **注意:1.6.0 版本开始,本接口不再维护。建议使用能力更强的 [Taro.createInnerAudioContext](./createInnerAudioContext) 接口**
|
|
999
|
+
* @supported weapp, harmony_hybrid
|
|
1000
|
+
* @example
|
|
1001
|
+
* ```tsx
|
|
1002
|
+
* const audioCtx = Taro.createAudioContext('myAudio')
|
|
1003
|
+
* ```
|
|
1004
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/wx.createAudioContext.html
|
|
1005
|
+
*/
|
|
1006
|
+
createAudioContext(
|
|
1007
|
+
/** [audio](/docs/components/media/audio) 组件的 id */
|
|
1008
|
+
id: string,
|
|
1009
|
+
/** 在自定义组件下,当前组件实例的this,以操作组件内 [audio](/docs/components/media/audio) 组件 */
|
|
1010
|
+
component?: TaroGeneral.IAnyObject,
|
|
1011
|
+
): AudioContext
|
|
1012
|
+
}
|
|
1013
|
+
}
|