このページは現在英語版のみで提供されており、日本語版も近日中に提供される予定です。ご利用いただきありがとうございます。

TUIAudioEffectManager

Introduction

TUIAudioEffectManager is a singleton object that manages background music, sound effects and vocal effects.
Installation
// npm
npm i @tencentcloud/tuiroom-engine-electron@2.4.0-alpha.3 --save

// pnpm
pnpm i @tencentcloud/tuiroom-engine-electron@2.4.0-alpha.3 --save

// yarn
yarn add @tencentcloud/tuiroom-engine-electron@2.4.0-alpha.3

Example code
import TUIRoomEngine, {
TUIAudioEffectManager, TUIVoiceReverbType, TUIVoiceChangerType
} from '@tencentcloud/tuiroom-engine-electron';

const audioEffectManager: TUIAudioEffectManager = TUIRoomEngine.getAudioEffectManager();
audioEffectManager.setVoiceReverbType(TUIVoiceReverbType.kVoiceReverbType_3);
audioEffectManager.setVoiceChangerType(TUIVoiceChangerType.kVoiceChangerType_1);

audioEffectManager.setMusicObserver({
onStart: (id: number, errCode: number)=>{
console.log(`music start play:`, id, errCode);
},
onPlayProgress: (id: number, curPtsMS: number, durationMS: number) => {
console.log(`music play progress:`, id, curPtsMS, durationMS);
},
onComplete: (id: number, errCode: number) => {
console.log(`music complete:`, id, errCode);
},
});
audioEffectManager.startPlayMusic({
id: 1,
path: 'https://web.sdk.qcloud.com/trtc/electron/download/resources/media/bgm/PositiveHappyAdvertising.mp3',
publish: true,
loopCount: 2,
isShortFile: false,
startTimeMS: 0,
endTimeMS: 0,
});

API

Method
Description
Set the reverb effect for vocals
Set the voice changer effect for vocals
Set the event callback for background music
Start playing background music
Stop playing background music
Pause playing background music
Resume playing background music
Set the local and remote volume levels for all background music
Set the remote volume level for a specific background music
Set the local volume level for a specific background music
Get the current playback position of the background music (in milliseconds)
Get the total duration of the background music (in milliseconds)
Set the playback position of the background music (in milliseconds)

Type Definitions

Type
Description
Background music playback control information
Background music playback event listener

Enumerations

Enum
Description
Voice reverb effect type
Voice changer effect type

API explaination

setVoiceReverbType

Set voice reverb effect type.
import TUIRoomEngine, {
TUIAudioEffectManager, TUIVoiceReverbType
} from '@tencentcloud/tuiroom-engine-electron';

const audioEffectManager: TUIAudioEffectManager = TUIRoomEngine.getAudioEffectManager();
audioEffectManager.setVoiceReverbType(TUIVoiceReverbType.kVoiceReverbType_3);
Parameters
Parameter
Type
Validation
Default value
Description
type
-
-
Voice reverb effect type
Return void

setVoiceChangerType

Set voice changer type.
import TUIRoomEngine, {
TUIAudioEffectManager, TUIVoiceChangerType
} from '@tencentcloud/tuiroom-engine-electron';

const audioEffectManager: TUIAudioEffectManager = TUIRoomEngine.getAudioEffectManager();
audioEffectManager.setVoiceChangerType(TUIVoiceChangerType.kVoiceChangerType_1);
Parameters
Parameter
Type
Validation
Default value
Description
type
-
-
Voice changer effect type
Return void

setMusicObserver

Set background music playback event listener
import TUIRoomEngine, {
TUIAudioEffectManager
} from '@tencentcloud/tuiroom-engine-electron';

const audioEffectManager: TUIAudioEffectManager = TUIRoomEngine.getAudioEffectManager();

audioEffectManager.setMusicObserver({
onStart: (id: number, errCode: number)=>{
console.log(`music start play:`, id, errCode);
},
onPlayProgress: (id: number, curPtsMS: number, durationMS: number) => {
console.log(`music play progress:`, id, curPtsMS, durationMS);
},
onComplete: (id: number, errCode: number) => {
console.log(`music complete:`, id, errCode);
},
});
Parameters
Parameter
Type
Validation
Default value
Description
observer
-
-
Background music playback event listener
Return void

startPlayMusic

Start playing background music.
import TUIRoomEngine, {
TUIAudioEffectManager
} from '@tencentcloud/tuiroom-engine-electron';

const audioEffectManager: TUIAudioEffectManager = TUIRoomEngine.getAudioEffectManager();

audioEffectManager.startPlayMusic({
id: 1,
path: 'https://web.sdk.qcloud.com/trtc/electron/download/resources/media/bgm/PositiveHappyAdvertising.mp3',
publish: true,
loopCount: 2,
isShortFile: false,
startTimeMS: 0,
endTimeMS: 0,
});
Parameters
Parameter
Type
Validation
Default value
Description
param
-
-
Background Music Parameters
Return void

stopPlayMusic

Stop playing background music.
Parameters
Parameter
Type
Validation
Default value
Description
id
number
-
-
Background music ID
Return void

pausePlayMusic

Pause background music.
Parameters
Parameter
Type
Validation
Default value
Description
id
number
-
-
Background music ID
Return void

resumePlayMusic

Resume background music.
Parameters
Parameter
Type
Validation
Default value
Description
id
number
-
-
Background music ID
Return void

setAllMusicVolume

Set all background musics playing and publishing volume.
Parameters
Parameter
Type
Validation
Default value
Description
volume
number
0-100
60
Music volume. Range:[0, 100]. Default value: 60.
Return void

setMusicPublishVolume

Set a music publishng volume.
Parameters
Parameter
Type
Validation
Default value
Description
id
number
-
-
Background music ID
volume
number
0-100
60
Music volume. Range:[0, 100]. Default value: 60.
Return void

setMusicPlayoutVolume

Set music playout volumne.
Parameters
Parameter
Type
Validation
Default value
Description
id
number
-
-
Background music ID
volume
number
0-100
60
Music volume. Range:[0, 100]. Default value: 60.
Return void

getMusicCurrentPosInMS

Get the current playback position of the background music (in milliseconds)
Parameters
Parameter
Type
Validation
Default value
Description
id
number
-
-
Background music ID
Return Promise<number> Current playing position in millisecnds. If it fails, return -1.

getMusicDurationInMS

Get the total duration of the background music (in milliseconds)
Parameters
Parameter
Type
Validation
Default value
Description
path
string
-
-
Music File Path
Return Promise<number> Total duration in milliseconds. If it fails, return -1.

seekMusicToPosInTime

Set the playback position of the background music (in milliseconds)
Parameters
Parameter
Type
Validation
Default value
Description
id
number
-
-
Background music ID
pts
number
-
-
Playing position in milliseconds
Return void

Type explaination

TUIAudioMusicParam

Background music playback control information
Field
Type
Description
id
number
Music ID. Multiple music tracks are allowed to be played, so an ID is needed to mark them for controlling the start, stop, volume, etc. of the music.
path
string
The full path or URL address of the audio file. Supported audio formats include MP3, AAC, M4A, WAV.
loopCount
number
Number of times the music is looped. The range is 0 - any positive integer, default value: 0. 0 means playing the music once; 1 means playing the music twice; and so on.
publish
boolean
Whether to transmit the music to the remote end. true: The music can be heard by remote users while playing locally; false: The anchor can only hear the music locally, and remote audiences cannot hear it. Default value: false.
isShortFile
boolean
Whether it is a short music file. true: A short music file that needs to be repeated; false: A normal music file. Default value: false.
startTimeMS
number
Music start playback time point, unit: milliseconds.
endTimeMS
number
Music end playback time point, unit milliseconds, 0 means play to the end of the file.

TUIMusicPlayObserver

Background music playback event listener type definition
Field
Type
Description
onStart
Function | null
Background music start playback event
onPlayProgress
Function | null
Background music playback progress event
onComplete
Function | null
Background music playback completion event
onStart
Parameter
Type
Description
id
number
Background music ID
errCode
number
Error code. 0: Playback started successfully; -4001: Failed to open file, such as unsupported audio file format, local audio file does not exist, network audio file cannot be accessed, etc.
onPlayProgress
Parameter
Type
Description
id
number
Background music ID
curPtsMS
number
Current playback timestamp of the background music
durationMS
number
Duration of the background music
onComplete
Parameter
Type
Description
id
number
Background music ID
errCode
number
Error code. 0: Playback ended; -4002: Decoding failed, such as corrupted audio file, network audio file server cannot be accessed, etc.

Enumerations explaination

TUIVoiceReverbType

Voice reverberation effects
Enumeration item
Type
Description
kVoiceReverbType_0
number
Off
kVoiceReverbType_1
number
KTV
kVoiceReverbType_2
number
Small room
kVoiceReverbType_3
number
Auditorium
kVoiceReverbType_4
number
Deep
kVoiceReverbType_5
number
Loud
kVoiceReverbType_6
number
Metallic
kVoiceReverbType_7
number
Magnetic
kVoiceReverbType_8
number
Ethereal
kVoiceReverbType_9
number
Studio
kVoiceReverbType_10
number
Mellow
kVoiceReverbType_11
number
Studio 2

TUIVoiceChangerType

Voice changer effects
Enumeration item
Type
Description
kVoiceChangerType_0
number
Off
kVoiceChangerType_1
number
Naughty child
kVoiceChangerType_2
number
Lolita
kVoiceChangerType_3
number
Uncle
kVoiceChangerType_4
number
Heavy metal
kVoiceChangerType_5
number
Cold
kVoiceChangerType_6
number
Foreign accent
kVoiceChangerType_7
number
Trapped beast
kVoiceChangerType_8
number
Otaku
kVoiceChangerType_9
number
Strong current
kVoiceChangerType_10
number
Heavy machinery
kVoiceChangerType_11
number
Ethereal