TRTC Web SDKAPI ReferenceEventsError CodesTypesTutorialsChangelog
中

Tutorial: Enable Voice Changer

Enable Voice Changer

Feature Description

This document describes how to use the Voice Changer Plugin.

Prerequisites

  • Pricing see RTC-Engine Packages.
  • TRTC Web SDK version >= 5.10
  • Supported browsers: Chrome 66+, Edge 79+, Safari 15+, Firefox 76+, Chrome for Android 126+

Implementation Process

1. Import and register the plugin

import { VoiceChanger } from 'trtc-sdk-v5/plugins/voice-changer';
let trtc = TRTC.create({ plugins: [VoiceChanger] });

2. Enable microphone

await trtc.startLocalAudio();

3. Use the voice changer plugin

await trtc.startPlugin('VoiceChanger', {
  voiceType: 1,
  sdkAppId: 123456,
  userId: 'user_123',
  userSig: 'XXXXXXXX'
});
// Update parameters after activation
await trtc.updatePlugin('VoiceChanger', {
  voiceType: 2,
});
// Disable the plugin before stopping microphone
await trtc.stopPlugin('VoiceChanger');
await trtc.stopLocalAudio();

API Reference

trtc.startPlugin('VoiceChanger', options)

Enable voice changing effects

options

Name Type Attributes Description
sdkAppId number Current application's sdkAppId
userId string Current user's userId
userSig string Current user's userSig
voiceType number Optional. 1-Mischievous Kid 2-Loli 3-Uncle 4-Heavy Metal 5-Cold 6-Foreign Accent 7-Caged Beast 8-Otaku 9-Strong Current 10-Heavy Machinery 11-Ethereal 12-Minions 13-Natural Male 14-Natural Female. When set, pitch and formantRatio are ignored.
pitch number Optional. Pitch offset, ranging from -1 to 1 (±12 semitones). Default: 0. Only effective when voiceType is not set.
formantRatio number Optional. Formant shift amount, ranging from -1 to 1. Positive values shift formants up, negative values shift them down. Default: 0. Only effective when voiceType is not set.

Note: At least one of voiceType, pitch, formantRatio is required, otherwise a parameter error is thrown.

Example:

await trtc.startLocalAudio();
await trtc.startPlugin('VoiceChanger', {
  voiceType: 1,
  sdkAppId: 123456,
  userId: 'user_123',
  userSig: 'XXXXXXXX'
});
// Omit voiceType to use custom pitch and formant
await trtc.startPlugin('VoiceChanger', {
  pitch: 0.2,
  formantRatio: -0.2,
  sdkAppId: 123456,
  userId: 'user_123',
  userSig: 'XXXXXXXX'
});

trtc.updatePlugin('VoiceChanger', options)

Modify voice changing effects

options

Name Type Attributes Description
voiceType number Optional. 1-Mischievous Kid 2-Loli 3-Uncle 4-Heavy Metal 5-Cold 6-Foreign Accent 7-Caged Beast 8-Otaku 9-Strong Current 10-Heavy Machinery 11-Ethereal 12-Minions 13-Natural Male 14-Natural Female. When set, pitch and formantRatio are ignored.
pitch number Optional. Pitch offset, ranging from -1 to 1 (±12 semitones). Only effective when voiceType is not set. If the current effect is a preset voiceType, the plugin switches to the custom voice effect first.
formantRatio number Optional. Formant shift amount, ranging from -1 to 1. Positive values shift formants up, negative values shift them down. Only effective when voiceType is not set. If the current effect is a preset voiceType, the plugin switches to the custom voice effect first.

Note: At least one of voiceType, pitch, formantRatio is required, otherwise a parameter error is thrown.

Example:

await trtc.updatePlugin('VoiceChanger', {
  voiceType: 2,
});
await trtc.updatePlugin('VoiceChanger', {
  pitch: 0.2,
  formantRatio: -0.2,
});

trtc.stopPlugin('VoiceChanger')

Disable voice changing effects

// Disable the plugin before stopping microphone
await trtc.stopPlugin('VoiceChanger');
await trtc.stopLocalAudio();