89
89
import io .agora .rtc2 .RtcEngineConfig ;
90
90
import io .agora .rtc2 .proxy .LocalAccessPointConfiguration ;
91
91
92
+ /**
93
+ * The type Voice effects.
94
+ */
92
95
@ Example (
93
96
index = 4 ,
94
97
group = ADVANCED ,
@@ -106,7 +109,7 @@ public class VoiceEffects extends BaseFragment implements View.OnClickListener,
106
109
private EditText et_channel ;
107
110
private Button join ;
108
111
private Spinner audioProfile , audioScenario ,
109
- chatBeautifier , timbreTransformation , voiceChanger , styleTransformation , roomAcoustics , pitchCorrection , _pitchModeOption , _pitchValueOption , voiceConversion , ainsMode ,
112
+ chatBeautifier , timbreTransformation , voiceChanger , styleTransformation , roomAcoustics , pitchCorrection , _pitchModeOption , _pitchValueOption , voiceConversion , ainsMode , voiceAITuner ,
110
113
customBandFreq , customReverbKey ;
111
114
private ViewGroup _voice3DLayout , _pitchModeLayout , _pitchValueLayout ;
112
115
private SeekBar _voice3DCircle , customPitch , customBandGain , customReverbValue , customVoiceFormant ;
@@ -154,6 +157,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
154
157
_pitchValueOption = view .findViewById (R .id .audio_pitch_value_option );
155
158
voiceConversion = view .findViewById (R .id .audio_voice_conversion );
156
159
ainsMode = view .findViewById (R .id .audio_ains_mode );
160
+ voiceAITuner = view .findViewById (R .id .voice_ai_tuner );
157
161
158
162
chatBeautifier .setOnItemSelectedListener (this );
159
163
timbreTransformation .setOnItemSelectedListener (this );
@@ -166,6 +170,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
166
170
_pitchModeOption .setOnItemSelectedListener (this );
167
171
_pitchValueOption .setOnItemSelectedListener (this );
168
172
ainsMode .setOnItemSelectedListener (this );
173
+ voiceAITuner .setOnItemSelectedListener (this );
169
174
170
175
// Customize Voice Effects Layout
171
176
customPitch = view .findViewById (R .id .audio_custom_pitch ); // engine.setLocalVoicePitch()
@@ -205,6 +210,7 @@ private void resetControlLayoutByJoined() {
205
210
_pitchValueLayout .setVisibility (View .GONE );
206
211
voiceConversion .setEnabled (joined );
207
212
ainsMode .setEnabled (joined );
213
+ voiceAITuner .setEnabled (joined );
208
214
209
215
customPitch .setEnabled (joined );
210
216
customBandFreq .setEnabled (joined );
@@ -238,30 +244,30 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
238
244
}
239
245
try {
240
246
RtcEngineConfig config = new RtcEngineConfig ();
241
- /**
247
+ /*
242
248
* The context of Android Activity
243
249
*/
244
250
config .mContext = context .getApplicationContext ();
245
- /**
251
+ /*
246
252
* The App ID issued to you by Agora. See <a href="https://docs.agora.io/en/Agora%20Platform/token#get-an-app-id"> How to get the App ID</a>
247
253
*/
248
254
config .mAppId = getString (R .string .agora_app_id );
249
- /** Sets the channel profile of the Agora RtcEngine.
255
+ /* Sets the channel profile of the Agora RtcEngine.
250
256
CHANNEL_PROFILE_COMMUNICATION(0): (Default) The Communication profile.
251
257
Use this profile in one-on-one calls or group calls, where all users can talk freely.
252
258
CHANNEL_PROFILE_LIVE_BROADCASTING(1): The Live-Broadcast profile. Users in a live-broadcast
253
259
channel have a role as either broadcaster or audience. A broadcaster can both send and receive streams;
254
260
an audience can only receive streams.*/
255
261
config .mChannelProfile = Constants .CHANNEL_PROFILE_LIVE_BROADCASTING ;
256
- /**
262
+ /*
257
263
* IRtcEngineEventHandler is an abstract class providing default implementation.
258
264
* The SDK uses this class to report to the app on SDK runtime events.
259
265
*/
260
266
config .mEventHandler = iRtcEngineEventHandler ;
261
267
config .mAudioScenario = Constants .AudioScenario .getValue (Constants .AudioScenario .DEFAULT );
262
- config .mAreaCode = ((MainApplication )getActivity ().getApplication ()).getGlobalSettings ().getAreaCode ();
268
+ config .mAreaCode = ((MainApplication ) getActivity ().getApplication ()).getGlobalSettings ().getAreaCode ();
263
269
engine = RtcEngine .create (config );
264
- /**
270
+ /*
265
271
* This parameter is for reporting the usages of APIExample to agora background.
266
272
* Generally, it is not necessary for you to set this parameter.
267
273
*/
@@ -288,7 +294,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
288
294
@ Override
289
295
public void onDestroy () {
290
296
super .onDestroy ();
291
- /** leaveChannel and Destroy the RtcEngine instance*/
297
+ /*leaveChannel and Destroy the RtcEngine instance*/
292
298
if (engine != null ) {
293
299
engine .leaveChannel ();
294
300
}
@@ -312,15 +318,14 @@ public void onClick(View v) {
312
318
AndPermission .with (this ).runtime ().permission (
313
319
Permission .Group .STORAGE ,
314
320
Permission .Group .MICROPHONE
315
- ).onGranted (permissions ->
316
- {
321
+ ).onGranted (permissions -> {
317
322
// Permissions Granted
318
323
joinChannel (channelId );
319
324
}).start ();
320
325
} else {
321
326
joined = false ;
322
327
resetControlLayoutByJoined ();
323
- /** After joining a channel, the user must call the leaveChannel method to end the
328
+ /*After joining a channel, the user must call the leaveChannel method to end the
324
329
* call before joining another channel. This method returns 0 if the user leaves the
325
330
* channel and releases all resources related to the call. This method call is
326
331
* asynchronous, and the user has not exited the channel when the method call returns.
@@ -389,21 +394,21 @@ private int getPitch2Value(String str) {
389
394
* Users that input the same channel name join the same channel.
390
395
*/
391
396
private void joinChannel (String channelId ) {
392
- /** In the demo, the default is to enter as the anchor.*/
397
+ /*In the demo, the default is to enter as the anchor.*/
393
398
engine .setClientRole (Constants .CLIENT_ROLE_BROADCASTER );
394
399
// audio config
395
400
engine .setAudioProfile (
396
401
Constants .AudioProfile .getValue (Constants .AudioProfile .valueOf (audioProfile .getSelectedItem ().toString ())),
397
402
Constants .AudioScenario .getValue (Constants .AudioScenario .valueOf (audioScenario .getSelectedItem ().toString ()))
398
403
);
399
404
400
- /** Please configure accessToken in the string_config file.
405
+ /*Please configure accessToken in the string_config file.
401
406
* A temporary token generated in Console. A temporary token is valid for 24 hours. For details, see
402
407
* https://docs.agora.io/en/Agora%20Platform/token?platform=All%20Platforms#get-a-temporary-token
403
408
* A token generated at the server. This applies to scenarios with high-security requirements. For details, see
404
409
* https://docs.agora.io/en/cloud-recording/token_server_java?platform=Java*/
405
410
TokenUtils .gen (requireContext (), channelId , 0 , accessToken -> {
406
- /** Allows a user to join a channel.
411
+ /* Allows a user to join a channel.
407
412
if you do not specify the uid, we will generate the uid for you*/
408
413
409
414
ChannelMediaOptions option = new ChannelMediaOptions ();
@@ -588,7 +593,7 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
588
593
589
594
for (Spinner spinner : voiceBeautifierSpinner ) {
590
595
if (spinner != parent ) {
591
- if (spinner .getSelectedItemPosition () != 0 ){
596
+ if (spinner .getSelectedItemPosition () != 0 ) {
592
597
spinner .setTag ("reset" );
593
598
spinner .setSelection (0 );
594
599
}
@@ -605,33 +610,33 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
605
610
606
611
for (Spinner spinner : audioEffectSpinner ) {
607
612
if (spinner != parent ) {
608
- if (spinner .getSelectedItemPosition () != 0 ){
613
+ if (spinner .getSelectedItemPosition () != 0 ) {
609
614
spinner .setTag ("reset" );
610
615
spinner .setSelection (0 );
611
616
}
612
617
}
613
618
}
614
619
615
- _voice3DLayout .setVisibility (audioEffectPreset == ROOM_ACOUSTICS_3D_VOICE ? View .VISIBLE : View .GONE );
620
+ _voice3DLayout .setVisibility (audioEffectPreset == ROOM_ACOUSTICS_3D_VOICE ? View .VISIBLE : View .GONE );
616
621
_pitchModeLayout .setVisibility (audioEffectPreset == PITCH_CORRECTION ? View .VISIBLE : View .GONE );
617
622
_pitchValueLayout .setVisibility (audioEffectPreset == PITCH_CORRECTION ? View .VISIBLE : View .GONE );
618
623
return ;
619
624
}
620
625
621
- if (parent == voiceConversion ){
626
+ if (parent == voiceConversion ) {
622
627
String item = parent .getSelectedItem ().toString ();
623
628
engine .setVoiceConversionPreset (getVoiceConversionValue (item ));
624
629
return ;
625
630
}
626
631
627
632
628
- if (parent == _pitchModeOption || parent == _pitchValueOption ){
633
+ if (parent == _pitchModeOption || parent == _pitchValueOption ) {
629
634
int effectOption1 = getPitch1Value (_pitchModeOption .getSelectedItem ().toString ());
630
635
int effectOption2 = getPitch2Value (_pitchValueOption .getSelectedItem ().toString ());
631
636
engine .setAudioEffectParameters (PITCH_CORRECTION , effectOption1 , effectOption2 );
632
637
}
633
638
634
- if (parent == ainsMode ){
639
+ if (parent == ainsMode ) {
635
640
boolean enable = position > 0 ;
636
641
/*
637
642
The AI noise suppression modes:
@@ -644,6 +649,12 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
644
649
*/
645
650
engine .setAINSMode (enable , position - 1 );
646
651
}
652
+
653
+ if (parent == voiceAITuner ) {
654
+ boolean enable = position > 0 ;
655
+ String item = parent .getSelectedItem ().toString ();
656
+ engine .enableVoiceAITuner (enable , enable ? Constants .VOICE_AI_TUNER_TYPE .valueOf (item ) : Constants .VOICE_AI_TUNER_TYPE .VOICE_AI_TUNER_MATURE_MALE );
657
+ }
647
658
}
648
659
649
660
private int getVoiceConversionValue (String label ) {
@@ -672,7 +683,7 @@ private int getVoiceConversionValue(String label) {
672
683
return VOICE_CHANGER_DARTH_VADER ;
673
684
case "VOICE_CHANGER_IRON_LADY" :
674
685
return VOICE_CHANGER_IRON_LADY ;
675
- case "VOICE_CHANGER_SHIN_CHAN" :
686
+ case "VOICE_CHANGER_SHIN_CHAN" :
676
687
return VOICE_CHANGER_SHIN_CHAN ;
677
688
case "VOICE_CHANGER_GIRLISH_MAN" :
678
689
return VOICE_CHANGER_GIRLISH_MAN ;
@@ -807,11 +818,11 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
807
818
if (!fromUser ) {
808
819
return ;
809
820
}
810
- if (seekBar == _voice3DCircle ){
821
+ if (seekBar == _voice3DCircle ) {
811
822
int cicle = (int ) (1 + 59 * progress * 1.0f / seekBar .getMax ());
812
823
// [1,60], 10 default
813
824
engine .setAudioEffectParameters (ROOM_ACOUSTICS_3D_VOICE , cicle , 0 );
814
- }else if (seekBar == customPitch ){
825
+ } else if (seekBar == customPitch ) {
815
826
double pitch = 0.5 + 1.5 * progress * 1.0f / seekBar .getMax ();
816
827
// pitch: [0.5,2.0], 1.0 default
817
828
engine .setLocalVoicePitch (pitch );
@@ -827,11 +838,11 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
827
838
// AUDIO_REVERB_ROOM_SIZE(2):[0, 100] dB
828
839
// AUDIO_REVERB_WET_DELAY(3):Wet signal, [0, 200] ms
829
840
// AUDIO_REVERB_STRENGTH(4): [0, 100]
830
- if (reverbKey == Constants .AUDIO_REVERB_TYPE .AUDIO_REVERB_DRY_LEVEL || reverbKey == Constants .AUDIO_REVERB_TYPE .AUDIO_REVERB_WET_LEVEL ){
841
+ if (reverbKey == Constants .AUDIO_REVERB_TYPE .AUDIO_REVERB_DRY_LEVEL || reverbKey == Constants .AUDIO_REVERB_TYPE .AUDIO_REVERB_WET_LEVEL ) {
831
842
value = (int ) (-20 + 30 * progress * 1.0f / seekBar .getMax ());
832
- }else if (reverbKey == Constants .AUDIO_REVERB_TYPE .AUDIO_REVERB_WET_DELAY ){
843
+ } else if (reverbKey == Constants .AUDIO_REVERB_TYPE .AUDIO_REVERB_WET_DELAY ) {
833
844
value = (int ) (200 * progress * 1.0f / seekBar .getMax ());
834
- }else {
845
+ } else {
835
846
value = (int ) (100 * progress * 1.0f / seekBar .getMax ());
836
847
}
837
848
engine .setLocalVoiceReverb (reverbKey , value );
0 commit comments