Skip to content

Commit b702906

Browse files
committed
添加变调接口,女声变男声可以设置pitch为-6
Change-Id: Ia5a03d39abffb9462014b6e235491bdf23c8dc88
1 parent 0837ed9 commit b702906

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

sdk/video-link-android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ android {
3636
}
3737

3838
dependencies {
39+
api fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
3940
implementation 'androidx.appcompat:appcompat:1.2.0'
4041
implementation 'com.google.android.material:material:1.2.1'
4142
testImplementation 'junit:junit:4.+'
493 KB
Binary file not shown.

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.text.TextUtils;
88
import android.util.Log;
99

10+
import com.iot.soundtouch.interfaces.SoundTouch;
1011
import com.tencent.iot.thirdparty.flv.FLVListener;
1112
import com.tencent.iot.thirdparty.flv.FLVPacker;
1213
import com.tencent.xnet.XP2P;
@@ -35,12 +36,15 @@ public class AudioRecordUtil implements EncoderListener, FLVListener {
3536
private int channel;
3637
private int bitDepth;
3738
private int channelCount; //声道数
39+
private int pitch; //变调【-12~12】
3840

3941
private boolean isRecord = false;
4042
private final ExecutorService executor = Executors.newSingleThreadExecutor();
4143
private String speakFlvFilePath = "/storage/emulated/0/speak.flv";
4244
private FileOutputStream fos;
4345

46+
private SoundTouch st;
47+
4448
public AudioRecordUtil(Context ctx, String id, int sampleRate) {
4549
context = ctx;
4650
deviceId = id;
@@ -51,6 +55,16 @@ public AudioRecordUtil(Context ctx, String id, int sampleRate, int channel, int
5155
deviceId = id;
5256
init(sampleRate, channel, bitDepth);
5357
}
58+
public AudioRecordUtil(Context ctx, String id, int sampleRate, int channel, int bitDepth, int pitch) {
59+
context = ctx;
60+
deviceId = id;
61+
this.pitch = pitch;
62+
init(sampleRate, channel, bitDepth);
63+
64+
if (st == null) {
65+
st = new SoundTouch(0,channelCount,sampleRate,bitDepth,1.0f, pitch);
66+
}
67+
}
5468

5569
private void init(int sampleRate, int channel, int bitDepth) {
5670
recordMinBufferSize = AudioRecord.getMinBufferSize(sampleRate, channel, bitDepth);
@@ -111,6 +125,13 @@ public void stop() {
111125
if (audioRecord != null) {
112126
audioRecord.stop();
113127
}
128+
129+
if (st != null) {
130+
st.finish();
131+
st.clearBuffer(0);
132+
st = null;
133+
}
134+
114135
executor.shutdown();
115136
audioRecord = null;
116137
pcmEncoder = null;
@@ -152,6 +173,10 @@ private class RecordThread extends Thread {
152173
public void run() {
153174
while (recorderState) {
154175
int read = audioRecord.read(buffer, 0, buffer.length);
176+
if (st != null) {
177+
st.putBytes(buffer);
178+
int bytesReceived = st.getBytes(buffer);
179+
}
155180
if (AudioRecord.ERROR_INVALID_OPERATION != read) {
156181
//获取到的pcm数据就是buffer了
157182
pcmEncoder.encodeData(buffer);

sdkdemo/src/main/java/com/tencent/iot/explorer/link/demo/video/preview/VideoPreviewActivity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.content.Context
66
import android.content.Intent
77
import android.content.pm.ActivityInfo
88
import android.graphics.SurfaceTexture
9+
import android.media.AudioFormat
910
import android.media.AudioManager
1011
import android.os.Bundle
1112
import android.os.Handler
@@ -137,6 +138,8 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
137138
tv_event_status.visibility = View.VISIBLE
138139
tv_event_status.setText(R.string.loading)
139140
audioRecordUtil = AudioRecordUtil(this, "${it.productId}/${presenter.getDeviceName()}", 16000)
141+
// //变调可以传入pitch参数
142+
// audioRecordUtil = AudioRecordUtil(this, "${it.productId}/${presenter.getDeviceName()}", 16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, -6)
140143
audioRecordUtil.recordSpeakFlv(true)
141144
}
142145

0 commit comments

Comments
 (0)