Skip to content

Commit

Permalink
Merge pull request #4 from MJLblabla/main
Browse files Browse the repository at this point in the history
1.0.6 升级语音转文字关闭时稳定性和光线活体
  • Loading branch information
MJLblabla authored Aug 18, 2021
2 parents 36e56f3 + b2ad5df commit 18d74bf
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 28 deletions.
3 changes: 1 addition & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ dependencies {
// 二维码扫描
implementation 'cn.yipianfengye.android:zxing-library:2.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation ('com.github.MJLblabla:hapiMediaPicker:1.0.5')
implementation files('libs/qndroid-rtc-3.1.0.jar')
// implementation project(":library")
implementation (files('libs/qndroid-rtc-ai-1.0.2.jar'))
implementation files('libs/qndroid-rtc-4.0.1-beta.5.jar')

implementation (files('libs/qndroid-rtc-ai-1.0.6.jar'))
implementation 'com.qiniu:happy-dns:0.2.17'
implementation 'com.qiniu:qiniu-java-sdk:7.6.0'
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
Expand Down
Binary file not shown.
Binary file removed app/libs/qndroid-rtc-ai-1.0.2.jar
Binary file not shown.
Binary file added app/libs/qndroid-rtc-ai-1.0.6.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ public class MainActivity extends AppCompatActivity {

private static final int QRCODE_RESULT_REQUEST_CODE = 1;
private EditText mRoomTokenEditText;
String token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iJ_cptTl3RbzLyca3t-AAiH-Hh:9ifJL3qnKSTAwuA1iPmDuOgnkRY=:eyJhcHBJZCI6ImQ4ZHJlOHcxcCIsImV4cGlyZUF0IjoxNjI3NzA0NDYwLCJwZXJtaXNzaW9uIjoidXNlciIsInJvb21OYW1lIjoiMTIzNCIsInVzZXJJZCI6ImFkc2Fkc2Fkc2EifQ=="

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class QnTrackAlDemo : Fragment() {
QNTextToSpeakAnalyzer.run(QNTTSParam().apply {
text = etText
audioEncoding = QNAudioEncoding.MP3
volume = 100
}
) {
tvText.text = "文转音:${it.errorCode} ${it.errorMsg}"
Expand Down
113 changes: 97 additions & 16 deletions app/src/main/java/com/qiniu/droid/rtc/sample1v1ai/RoomActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.Toast;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentTransaction;

import com.qiniu.droid.rtc.QNCustomMessage;
import com.qiniu.droid.rtc.QNAudioFrame;
import com.qiniu.droid.rtc.QNAudioFrameListener;
import com.qiniu.droid.rtc.QNCameraSwitchResultCallback;
import com.qiniu.droid.rtc.QNCameraVideoTrackConfig;
import com.qiniu.droid.rtc.QNClientEventListener;
Expand All @@ -20,14 +24,20 @@
import com.qiniu.droid.rtc.QNPublishResultCallback;
import com.qiniu.droid.rtc.QNRTC;
import com.qiniu.droid.rtc.QNRTCClient;
import com.qiniu.droid.rtc.QNRTCEngine;
import com.qiniu.droid.rtc.QNRTCEventListener;
import com.qiniu.droid.rtc.QNRTCSetting;
import com.qiniu.droid.rtc.QNScreenVideoTrackConfig;
import com.qiniu.droid.rtc.QNSurfaceView;
import com.qiniu.droid.rtc.QNTrack;
import com.qiniu.droid.rtc.QNVideoFormat;
import com.qiniu.droid.rtc.model.QNAudioDevice;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.List;

public class RoomActivity extends AppCompatActivity implements QNRTCEventListener, QNClientEventListener {
Expand All @@ -37,6 +47,7 @@ public class RoomActivity extends AppCompatActivity implements QNRTCEventListene

private QNSurfaceView mLocalVideoSurfaceView;
private QNSurfaceView mRemoteVideoSurfaceView;
private QNRTCSetting mSetting;
private QNRTCClient mClient;
private String mRoomToken;

Expand All @@ -50,6 +61,7 @@ public class RoomActivity extends AppCompatActivity implements QNRTCEventListene
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_room);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

mLocalVideoSurfaceView = findViewById(R.id.local_video_surface_view);
mRemoteVideoSurfaceView = findViewById(R.id.remote_video_surface_view);
Expand All @@ -58,22 +70,22 @@ protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
mRoomToken = intent.getStringExtra("roomToken");

QNRTCSetting setting = new QNRTCSetting();
mSetting = new QNRTCSetting();

// 配置默认摄像头 ID,此处配置为前置摄像头
setting.setCameraID(QNRTCSetting.QNCameraFacing.FRONT);
mSetting.setCameraID(QNRTCSetting.QNCameraFacing.FRONT);

// 相机预览分辨率、帧率配置为 640x480、20fps
setting.setCameraPreviewFormat(new QNVideoFormat(640, 480, 30));
mSetting.setCameraPreviewFormat(new QNVideoFormat(640, 480, 30));

// 初始化 QNRTC
QNRTC.init(getApplicationContext(), setting, this);
QNRTC.init(getApplicationContext(), mSetting, this);

// 创建本地 Camera 采集 track
if (mLocalVideoTrack == null) {
QNCameraVideoTrackConfig cameraVideoTrackConfig = new QNCameraVideoTrackConfig(TAG_CAMERA)
.setVideoEncodeFormat(new QNVideoFormat(640, 480, 30))
.setBitrate(1200 * 1000);
.setBitrate(1200);
mLocalVideoTrack = QNRTC.createCameraVideoTrack(cameraVideoTrackConfig);
}
// 设置预览窗口
Expand All @@ -82,7 +94,7 @@ protected void onCreate(Bundle savedInstanceState) {
// 创建本地音频采集 track
if (mLocalAudioTrack == null) {
QNMicrophoneAudioTrackConfig microphoneAudioTrackConfig = new QNMicrophoneAudioTrackConfig(TAG_MICROPHONE)
.setBitrate(100 * 1000);
.setBitrate(100);
mLocalAudioTrack = QNRTC.createMicrophoneAudioTrack(microphoneAudioTrackConfig);
}

Expand Down Expand Up @@ -125,6 +137,9 @@ public void onError(int errorCode, String errorMessage) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.flCover, flCover);
transaction.commit();

QNTrack track = QNRTC.createCustomAudioTrack();

}

@Override
Expand All @@ -137,7 +152,6 @@ protected void onDestroy() {
/**
* 房间状态改变时会回调此方法
* 房间状态回调只需要做提示用户,或者更新相关 UI; 不需要再做加入房间或者重新发布等其他操作!
*
* @param state 房间状态,可参考 {@link QNConnectionState}
*/
@Override
Expand Down Expand Up @@ -176,10 +190,10 @@ public void onLeft() {

/**
* 远端用户加入房间时会回调此方法
* @see QNRTCClient#join(String, String, QNJoinResultCallback) 可指定 userData 字段
*
* @param remoteUserId 远端用户的 userId
* @param userData 透传字段,用户自定义内容
* @see QNRTCClient#join(String, String, QNJoinResultCallback) 可指定 userData 字段
* @param userData 透传字段,用户自定义内容
*/
@Override
public void onUserJoined(String remoteUserId, String userData) {
Expand Down Expand Up @@ -220,7 +234,7 @@ public void onUserLeft(String remoteUserId) {
* 远端用户 tracks 成功发布时会回调此方法
*
* @param remoteUserId 远端用户 userId
* @param trackList 远端用户发布的 tracks 列表
* @param trackList 远端用户发布的 tracks 列表
*/
@Override
public void onUserPublished(String remoteUserId, List<QNTrack> trackList) {
Expand All @@ -231,7 +245,7 @@ public void onUserPublished(String remoteUserId, List<QNTrack> trackList) {
* 远端用户 tracks 成功取消发布时会回调此方法
*
* @param remoteUserId 远端用户 userId
* @param trackList 远端用户取消发布的 tracks 列表
* @param trackList 远端用户取消发布的 tracks 列表
*/
@Override
public void onUserUnpublished(String remoteUserId, List<QNTrack> trackList) {
Expand All @@ -248,7 +262,7 @@ public void onUserUnpublished(String remoteUserId, List<QNTrack> trackList) {
* 成功订阅远端用户的 tracks 时会回调此方法
*
* @param remoteUserId 远端用户 userId
* @param trackList 订阅的远端用户 tracks 列表
* @param trackList 订阅的远端用户 tracks 列表
*/
@Override
public void onSubscribed(String remoteUserId, List<QNTrack> trackList) {
Expand All @@ -264,6 +278,11 @@ public void onSubscribed(String remoteUserId, List<QNTrack> trackList) {
}
}

@Override
public void onMessageReceived(QNCustomMessage qnCustomMessage) {

}

/**
* 当音频路由发生变化时会回调此方法
*
Expand All @@ -277,7 +296,7 @@ public void onPlaybackDeviceChanged(QNAudioDevice qnAudioDevice) {
/**
* 系统相机出错时会触发此回调
*
* @param errorCode 错误码
* @param errorCode 错误码
* @param errorMessage 错误原因
*/
@Override
Expand Down Expand Up @@ -331,6 +350,7 @@ public void onError(int errorCode, String errorMessage) {

public void clickSwitchCamera(View view) {
final ImageButton button = (ImageButton) view;

// 切换摄像头
QNRTC.switchCamera(new QNCameraSwitchResultCallback() {
@Override
Expand All @@ -345,6 +365,7 @@ public void run() {

@Override
public void onCameraSwitchError(String errorMessage) {

}
});
}
Expand All @@ -356,4 +377,64 @@ public void clickHangUp(View view) {
QNRTC.deinit();
finish();
}
}

private static class ClientPcmRecorder {

private QNRTCClient client;
private String dstPath = null;
private File pcmFile = null;
private BufferedOutputStream bos = null;
private QNAudioFrameListener listener = new QNAudioFrameListener() {
@Override
public void onAudioFrameAvailable(QNAudioFrame audioFrame) {
writeAudioData(audioFrame.buffer, audioFrame.size, audioFrame.format.getBitsPerSample(), audioFrame.format.getSampleRate(), audioFrame.format.getChannels());
}
};

private ClientPcmRecorder(QNRTCClient client, String dstPath) {
this.client = client;
this.dstPath = dstPath;
}

public boolean startRecordAudio() {
try {
pcmFile = new File(dstPath);
if (pcmFile.exists()) {
pcmFile.delete();
}
bos = new BufferedOutputStream(new FileOutputStream(pcmFile));
} catch (FileNotFoundException e) {
e.printStackTrace();
bos = null;
pcmFile = null;
return false;
}
client.addAllAudioDataMixedListener(listener);
return true;
}

public void stopAudioRecord() {
client.removeAllAudioDataMixedListener(listener);
if (bos != null) {
try {
bos.flush();
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
bos = null;
pcmFile = null;
}

private void writeAudioData(ByteBuffer audioData, int size, int bitsPerSample, int sampleRate, int numberOfChannels) {
try {
Log.d(TAG, "client pcm recording --> size="+size + ",bitsPerSample="+bitsPerSample + ",sampleRate=" + sampleRate + ",numberOfChannels="+numberOfChannels);
bos.write(audioData.array(), 0, size);
} catch (IOException e) {
e.printStackTrace();
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ public class TokenUtils {

private static final String ENCODING = "UTF-8";

static String appKey = "";
static String appId = "";
static String appSecretKey = "";
static String appKey = "bsOUqUaLN-cJ3DlmdD6jU8B7_Nq5fo6IDZVAhtLe";
static String appId = "testApp";
static String appSecretKey = "B8IUczRc8wlbttCxesVLzS0pEWZ_aKEQ63Cz9CzR";


public static String resetToken() {

Expand All @@ -33,4 +34,4 @@ public static String resetToken() {
public static String signUrlToToken(String url) {
return Auth.create(appKey, appSecretKey).sign(url);// "${appKey}:${sha1}"
}
}
}

0 comments on commit 18d74bf

Please sign in to comment.