Skip to content

Commit fed99ec

Browse files
committed
凯迪仕变声添加mode接口
Change-Id: I795691a445bcbfecf1cc45c7b17004f4fa36619f
1 parent 754d1ce commit fed99ec

File tree

3 files changed

+55
-11
lines changed

3 files changed

+55
-11
lines changed

sdk/video-link-android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ dependencies {
5151
api 'com.tencent.iot.thirdparty.android:xp2p-sdk:2.4.34'
5252
api 'com.tencent.iot.thirdparty.android:media-server:1.0.5'
5353
api 'io.github.sundoggynew:iot-soundtouch:1.0.0'
54+
api 'io.github.sundoggynew:iot-voice-changer:1.0.0'
5455
}
5556

5657
configurations.all {

sdk/video-link-android/src/main/java/com/tencent/iot/video/link/util/audio/AudioRecordUtil.java

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.util.Log;
1111

1212
import com.iot.soundtouch.interfaces.SoundTouch;
13+
import com.iot.voice.changer.VoiceChangerJNIBridge;
1314
import com.tencent.iot.thirdparty.flv.FLVListener;
1415
import com.tencent.iot.thirdparty.flv.FLVPacker;
1516
import com.tencent.xnet.XP2P;
@@ -40,7 +41,9 @@ public class AudioRecordUtil implements EncoderListener, FLVListener {
4041
private int channel;
4142
private int bitDepth;
4243
private int channelCount; //声道数
44+
private int encodeBit; //位深
4345
private int pitch = 0; //变调【-12~12】
46+
private VoiceChangerMode mode = VoiceChangerMode.VOICE_CHANGER_MODE_NONE;
4447
private boolean enableAEC = false;
4548
private boolean enableAGC = false;
4649

@@ -93,6 +96,12 @@ private void init(int sampleRate, int channel, int bitDepth) {
9396
} else if (channel == AudioFormat.CHANNEL_IN_STEREO) {
9497
this.channelCount = 2;
9598
}
99+
if (bitDepth == AudioFormat.ENCODING_PCM_16BIT) {
100+
this.encodeBit = 16;
101+
} else if (bitDepth == AudioFormat.ENCODING_PCM_8BIT) {
102+
this.encodeBit = 8;
103+
}
104+
recordMinBufferSize = (sampleRate*this.channelCount*this.encodeBit/8)/1000*20; //20ms数据长度
96105
Log.e(TAG, "AudioRecordUtil init Pitch is: "+ pitch);
97106
}
98107

@@ -124,13 +133,30 @@ public void setPitch(int pitch) {
124133
this.pitch = pitch;
125134
}
126135

136+
public void setMode(VoiceChangerMode mode) {
137+
Log.e(TAG, "setMode is: "+ mode);
138+
this.mode = mode;
139+
if (mode == VoiceChangerMode.VOICE_CHANGER_MODE_MAN) {
140+
this.pitch = -6;
141+
} else if (mode == VoiceChangerMode.VOICE_CHANGER_MODE_WOMAN) {
142+
this.pitch = 6;
143+
} else {
144+
this.pitch = 0;
145+
}
146+
}
147+
127148
/**
128149
* 开始录制
129150
*/
130151
public void start() {
131152
reset();
132-
if (st == null) {
133-
st = new SoundTouch(0,channelCount,sampleRate,bitDepth,1.0f, pitch);
153+
if (!VoiceChangerJNIBridge.isAvailable()) {
154+
if (st == null) {
155+
st = new SoundTouch(0,channelCount,sampleRate,bitDepth,1.0f, pitch);
156+
}
157+
} else {
158+
VoiceChangerJNIBridge.init(sampleRate,channelCount);
159+
VoiceChangerJNIBridge.setMode(this.mode.getValue());
134160
}
135161
recorderState = true;
136162
audioRecord.startRecording();
@@ -164,12 +190,6 @@ public void stop() {
164190
audioRecord.stop();
165191
}
166192

167-
if (st != null) {
168-
st.finish();
169-
st.clearBuffer(0);
170-
st = null;
171-
}
172-
173193
executor.shutdown();
174194
audioRecord = null;
175195
pcmEncoder = null;
@@ -185,6 +205,16 @@ public void stop() {
185205
control.release();
186206
control = null;
187207
}
208+
209+
if (!VoiceChangerJNIBridge.isAvailable()) {
210+
if (st != null) {
211+
st.finish();
212+
st.clearBuffer(0);
213+
st = null;
214+
}
215+
} else {
216+
VoiceChangerJNIBridge.destory();
217+
}
188218
}
189219

190220
public void release() {
@@ -221,9 +251,15 @@ private class RecordThread extends Thread {
221251
public void run() {
222252
while (recorderState) {
223253
int read = audioRecord.read(buffer, 0, buffer.length);
224-
if (pitch != 0 && st != null) {
225-
st.putBytes(buffer);
226-
int bytesReceived = st.getBytes(buffer);
254+
if (!VoiceChangerJNIBridge.isAvailable()) {
255+
if (pitch != 0 && st != null) {
256+
st.putBytes(buffer);
257+
int bytesReceived = st.getBytes(buffer);
258+
}
259+
} else {
260+
if (pitch != 0) {
261+
VoiceChangerJNIBridge.voiceChangerRun(buffer, buffer, buffer.length/(encodeBit/8));
262+
}
227263
}
228264
if (AudioRecord.ERROR_INVALID_OPERATION != read) {
229265
//获取到的pcm数据就是buffer了
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.tencent.iot.video.link.util.audio
2+
3+
enum class VoiceChangerMode (val value: Int) {
4+
VOICE_CHANGER_MODE_NONE(0),
5+
VOICE_CHANGER_MODE_WOMAN(2) ,
6+
VOICE_CHANGER_MODE_MAN(3) ;
7+
}

0 commit comments

Comments
 (0)