tencent cloud

Feedback

Last updated: 2024-11-21 18:48:12

    stopVoice

    This API is used via wx.stopVoice(Object object).
    Feature Description: Terminates the playback of audio.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    wx.startRecord({
    success (res) {
    const tempFilePath = res.tempFilePath
    wx.playVoice({
    filePath: tempFilePath,
    })
    
    setTimeout(() => { wx.stopVoice() }, 5000)
    }
    })

    playVoice

    This API is used via wx.playVoice(Object object).
    Feature Description: Starts the playback of voice. Only one voice file is permitted to play at a time. If a previous voice file is still playing, it will be interrupted.
    Parameter and Description:
    Attribute
    Type
    Default value
    Required
    Description
    filePath
    string
    -
    Yes
    Path of the audio file to be played (local path)
    duration
    number
    60
    No
    Specifies the playback duration. Upon reaching the specified duration, the playback will automatically cease. Unit: seconds.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    wx.startRecord({
    success (res) {
    const tempFilePath = res.tempFilePath
    wx.playVoice({
    filePath: tempFilePath,
    complete () { }
    })
    }
    })

    pauseVoice

    This API is used via wx.pauseVoice(Object object).
    Feature Description: Pauses the currently playing audio. When wx.playVoice is called again to play the same file, it will resume from the point of pause. If playback is to start from the beginning, wx.stopVoice must be called first.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    wx.startRecord({
    success (res) {
    const tempFilePath = res.tempFilePath
    wx.playVoice({
    filePath: tempFilePath
    })
    
    setTimeout(() => { wx.pauseVoice() }, 5000)
    }
    })

    setInnerAudioOption

    This API is used via wx.setInnerAudioOption(Object object).
    Feature Description: Sets the playback options for InnerAudioContext. Once set, it applies globally to the current mini program.
    Parameter: Object.
    Attribute
    Type
    Default value
    Required
    Description
    mixWithOther
    boolean
    true
    No
    Whether to mix with other audio. When set to true, it will not terminate the music of other applications.
    obeyMuteSwitch
    boolean
    true
    No
    (Effective only on iOS) Whether to adhere to the mute switch. When set to false, sound can be played even in mute mode.
    speakerOn
    boolean
    true
    No
    true for playback from speakers, false for playback from earpiece, default value is true
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)

    getAvailableAudioSources

    This API is used via wx.getAvailableAudioSources(Object object).
    Feature Description: Gets the currently supported audio input sources.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function:
    Attribute
    Type
    Description
    audioSources
    Array.<string>
    List of supported audio input sources. See AudioSource for the definition of return values.
    Valid values for audioSources
    Valid Values
    Description
    auto
    Automatically configured to default to the mobile microphone. Upon connecting a headset, it automatically switches to the headset microphone. Applicable across all platforms.
    buildInMic
    Mobile microphone, exclusive to iOS.
    headsetMic
    Headset microphone, exclusive to iOS.
    mic
    Microphone (defaults to mobile microphone when headset is not connected, switches to headset microphone when connected), exclusive to Android.
    camcorder
    Similar to the microphone, applicable for recording audio and video content, exclusive to Android.
    voice_communication
    Similar to the microphone, applicable for real-time communications, exclusive to Android.
    voice_recognition
    Similar to the microphone, applicable for recording audio content, exclusive to Android.

    createAudioContext

    This API is used via AudioContext wx.createAudioContext(string id, Object this).
    Feature Description: Creates anAudioContext object.
    Parameter and Description: string id, ID of the audio component; Object this, "this" of the current component instance under custom components, used to operate the audio component within.
    Return Value: AudioContext
    Note: InnerAudioContext audio resources will not be automatically released, so if you no longer need to use the audio, please call InnerAudioContext.destroy() to release the resources in time to avoid memory leakage.
    Sample code:
    const innerAudioContext = wx.createInnerAudioContext()
    innerAudioContext.src = 'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46'
    
    innerAudioContext.play() // play
    
    
    innerAudioContext.pause() // pause
    
    
    innerAudioContext.stop() // stops
    
    
    innerAudioContext.destroy() // free the audio resource
    

    AudioContext

    An AudioContext instance can be obtained through wx.createAudioContext. It binds with an audio component through an id, allowing operations on the corresponding audio component.

    createInnerAudioContext

    This API is used via InnerAudioContext wx.createInnerAudioContext(Object object).
    Feature Description: Creates an internal audio context InnerAudioContext object, with the usage method being wx.createInnerAudioContext().
    Return Value: InnerAudioContext.
    

    InnerAudioContext

    Attributes

    string src: The address of the audio resource, used for direct playback. Cloud file ID is supported.
    number startTime: The starting position for playback (in seconds), defaulting to 0.
    boolean autoplay: Determines whether playback starts automatically, defaulting to "false".
    boolean loop: Determines whether the playback circulates, defaulting to "false".
    number volume: Volume level, ranging from 0 to 1, defaulting to 1.
    number duration: The length of the current audio (in seconds). Only returned when there is a valid src (read-only).
    number currentTime: The current playback position of the audio (in seconds). Only returned when there is a valid src, and the time is accurate to 6 decimal places (read-only).
    boolean paused: Indicates whether the current status is paused or stopped (read-only).
    number buffered: The time point that the audio is buffered to, ensuring content from the current playback point to this point has been buffered (read-only).

    Supported format

    Format
    iOS
    Android
    flac
    x
    m4a
    ogg
    x
    ape
    x
    amr
    x
    wma
    x
    wav
    mp3
    mp4
    x
    aac
    aiff
    x
    caf
    x

    Sample code

    const innerAudioContext = wx.createInnerAudioContext()
    innerAudioContext.autoplay = true
    innerAudioContext.src = 'https://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46'
    innerAudioContext.onPlay(() => {
    console.log('Start playback')
    })
    innerAudioContext.onError((res) => {
    console.log(res.errMsg)
    console.log(res.errCode)
    })

    Method Set

    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support