Skip to content

Commit

Permalink
fix(types): align WebAudioContext.decodeAudioData signature with WeCh…
Browse files Browse the repository at this point in the history
…at docs

Updated the `decodeAudioData` method in `WebAudioContext` to match the official WeChat Mini Program documentation:
- Modified the return type to `Promise<AudioBuffer>` instead of `AudioBuffer`, because of this method' actual response.
- Adjusted method parameters to accept `audioData`, `successCallback`, and `errorCallback`.

This fixes the TypeScript error and aligns the implementation with the expected API behavior.
Closes NervJS#17080
  • Loading branch information
BH4HPA committed Dec 25, 2024
1 parent 7121844 commit a9af6ca
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions packages/taro/types/api/media/audio.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ declare module '../../index' {
/** 支持的音频输入源 */
interface audioSources {
/** 自动设置,默认使用手机麦克风,插上耳麦后自动切换使用耳机麦克风,所有平台适用 */
'auto'
auto
/** 手机麦克风,仅限 iOS */
'buildInMic'
buildInMic
/** 耳机麦克风,仅限 iOS */
'headsetMic'
headsetMic
/** 麦克风(没插耳麦时是手机麦克风,插耳麦时是耳机麦克风),仅限 Android */
'mic'
mic
/** 同 mic,适用于录制音视频内容,仅限 Android */
'camcorder'
camcorder
/** 同 mic,适用于实时沟通,仅限 Android */
'voice_communication'
voice_communication
/** 同 mic,适用于语音识别,仅限 Android */
'voice_recognition'
voice_recognition
}
}

Expand Down Expand Up @@ -180,15 +180,15 @@ declare module '../../index' {
*/
seek(
/** 跳转位置,单位 s */
position: number,
position: number
): void
/** 设置音频地址
* @supported weapp
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/AudioContext.setSrc.html
*/
setSrc(
/** 音频地址 */
src: string,
src: string
): void
}
/** InnerAudioContext 实例,可通过 [Taro.createInnerAudioContext](./createInnerAudioContext) 接口获取实例。
Expand Down Expand Up @@ -740,7 +740,11 @@ declare module '../../index' {
* ```
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.decodeAudioData.html
*/
decodeAudioData(): AudioBuffer
decodeAudioData(
audioData: ArrayBuffer,
successCallback: (buffer: AudioBuffer) => void,
errorCallback: (error: any) => void
): Promise<AudioBuffer>
}

namespace WebAudioContext {
Expand Down Expand Up @@ -887,7 +891,9 @@ declare module '../../index' {
* @supported weapp
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/wx.getAvailableAudioSources.html
*/
getAvailableAudioSources(option?: getAvailableAudioSources.Option): Promise<getAvailableAudioSources.SuccessCallbackResult>
getAvailableAudioSources(
option?: getAvailableAudioSources.Option
): Promise<getAvailableAudioSources.SuccessCallbackResult>

/** 创建 WebAudio 上下文。
* @supported weapp
Expand Down Expand Up @@ -1003,7 +1009,7 @@ declare module '../../index' {
/** [audio](/docs/components/media/audio) 组件的 id */
id: string,
/** 在自定义组件下,当前组件实例的this,以操作组件内 [audio](/docs/components/media/audio) 组件 */
component?: TaroGeneral.IAnyObject,
component?: TaroGeneral.IAnyObject
): AudioContext
}
}

0 comments on commit a9af6ca

Please sign in to comment.