Tutorial: Implement voice change

Implement voice change

Introduction

rtc-voice-changer is used to change the voice of TRTC's audio and video calls.

Prerequisites

For usage fee instructions, please see TRTC Edition Features and Pricing.

Supported browsers: Chrome 66+, Edge 79+, Safari 14.1+, Firefox 76+.

For better use of rtc-voice-changer, it is recommended that you use the latest version of Chrome.

Installation

npm install rtc-voice-changer

Feature Description

Step 1. Initialize RTCVoiceChanger

import RTCVoiceChanger from 'rtc-voice-changer';
const voiceChanger = new RTCVoiceChanger();

Step 2. Create a processor instance to process audio and video streams

A processor can only process one stream.

let localStream = TRTC.createStream({ audio: true, video: true });
await localStream.initialize();
const voiceChangerProcessor = await voiceChanger.createProcessor({ userId, sdkAppId, userSig });
// 1-Brat 2-Loli 3-Uncle 4-Heavy Metal 5-Cold 6-Foreign Accent 7-Beast 8-Fat Otaku 9-Strong Current 10-Heavy Machinery 11-Ethereal
await voiceChangerProcessor.process(localStream, 1);
// Switch effects midway
await voiceChangerProcessor.setEffect(3);

Step 3. End the call close processor and release resources

await client.leave();
await voiceChangerProcessor.close();
voiceChangerProcessor.destroy();

API

RTCVoiceChanger

Create a plugin instance

const rtcVoiceChanger = new RTCVoiceChanger();

createProcessor(params)

Create a Processor instance

const voiceChangerProcessor = await rtcVoiceChanger.createProcessor({
  sdkAppId,
  userId,
  userSig
});

Params:

Name Type Description
sdkAppId number sdkAppId
Get the sdkAppId information in Application Information after creating a new application by clicking Application Management > Create Application in the Real-Time Audio and Video Console.
userId string User ID
It is recommended to limit the length to 32 bytes, and only allow uppercase and lowercase English letters (a-zA-Z), numbers (0-9), underscores, and hyphens.
userSig string UserSig signature
Refer to UserSig Related for how to calculate userSig.

Processor

process(localStream, voiceType)

Add noise reduction effect to the audio of the local stream.

Params:

Name Type Description
localStream LocalStream Local stream.
voiceType number 1-Brat 2-Loli 3-Uncle 4-Heavy Metal 5-Cold 6-Foreign Accent 7-Beast 8-Fat Otaku 9-Strong Current 10-Heavy Machinery 11-Ethereal.
await voiceChangerProcessor.process(localStream, 1);

setEffect(type)

Switch effects.

Name Type Description
voiceType number 1-Brat 2-Loli 3-Uncle 4-Heavy Metal 5-Cold 6-Foreign Accent 7-Beast 8-Fat Otaku 9-Strong Current 10-Heavy Machinery 11-Ethereal.
await voiceChangerProcessor.setEffect(2);

setPitch(pitch)

Set the pitch.

Name Type Description
pitch number Set the pitch, 0 means normal, negative number lowers the pitch, positive number raises the pitch. Suggested range -1 ~ 1
await voiceChangerProcessor.setPitch(-0.5);

close()

Turn off the voice changing effect, Replace localStream's changed audio track with the original audio track.

await voiceChangerProcessor.close();

destroy()

Destroy the processor and release resources, ending the processor's lifecycle.

voiceChangerProcessor.destroy();

Changelog

Version 1.0.1 @2023.7.7

Improvement

Optimising performance issues.

Version 1.0.0 @2023.06.20

Official Release 1.0.0