Skip to content

Commit

Permalink
Merge pull request #30 from MJLblabla/main
Browse files Browse the repository at this point in the history
升级语音识别sdk
  • Loading branch information
MJLblabla authored Mar 27, 2024
2 parents 78dc45d + 5679749 commit 158a321
Show file tree
Hide file tree
Showing 44 changed files with 192 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

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

10 changes: 10 additions & 0 deletions .idea/deploymentTargetDropDown.xml

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

5 changes: 2 additions & 3 deletions .idea/gradle.xml

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

10 changes: 10 additions & 0 deletions .idea/migrations.xml

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

3 changes: 2 additions & 1 deletion .idea/misc.xml

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

2 changes: 1 addition & 1 deletion .idea/vcs.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.qiniu.droid.rtc.sample1v1ai
import android.content.Context
import android.text.TextUtils
import android.util.Log
import com.qiniu.droid.rtc.ai.ASRConfig
import com.qiniu.droid.rtc.ai.QNRtcAISdkManager
import com.qiniu.droid.rtc.ai.core.util.JsonUtils
import com.qiniu.droid.rtc.sample1v1ai.http.OKHttpManger
Expand All @@ -12,6 +13,7 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import okhttp3.Request
import java.util.UUID

object AISdkManager {

Expand Down Expand Up @@ -46,9 +48,12 @@ object AISdkManager {
return
}
isInit = true
QNRtcAISdkManager.setSignCallback {
""// TokenUtils.signUrlToToken(it)
}

QNRtcAISdkManager.setASRParams(ASRConfig().apply {
asrAppID = 1
asrAppKey = ""
asrCUid = "13141616037"
})
GlobalScope.launch(Dispatchers.Main) {
val ret = async(Dispatchers.IO) {
getToken("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ public class MainActivity extends AppCompatActivity {

private static final int QRCODE_RESULT_REQUEST_CODE = 1;
private EditText mRoomTokenEditText;
String token1 = "QxZugR8TAhI38AiJ_cptTl3RbzLyca3t-AAiH-Hh:h2tMZMPdW6Rbih3nbAGxqFl0QzI=:eyJhcHBJZCI6ImZuZjB2cjZnbiIsImV4cGlyZUF0IjoxNzMzOTc0MzQ0LCJwZXJtaXNzaW9uIjoidXNlciIsInJvb21OYW1lIjoiYWRzYWQiLCJ1c2VySWQiOiJkc2FkYWQifQ==";
String token2 = "QxZugR8TAhI38AiJ_cptTl3RbzLyca3t-AAiH-Hh:y9b4TYJbHr2gzaTH45r6mASBm4c=:eyJhcHBJZCI6ImZuZjB2cjZnbiIsImV4cGlyZUF0IjoxNzMzOTc0MzQ0LCJwZXJtaXNzaW9uIjoidXNlciIsInJvb21OYW1lIjoiYWRzYWQiLCJ1c2VySWQiOiJkc2FkYWRkc2RzYWRhIn0=";
String token1 = "QxZugR8TAhI38AiJ_cptTl3RbzLyca3t-AAiH-Hh:HZmhytVxpX3YpeP-5wPoTWAeJBU=:eyJhcHBJZCI6ImQ4ZHJlOHcxcCIsImV4cGlyZUF0IjoxNzQxNDIzMzYyLCJwZXJtaXNzaW9uIjoidXNlciIsInJvb21OYW1lIjoiMTIzMTIzIiwidXNlcklkIjoiMTIzMTIzIn0=";
String token2 = "QxZugR8TAhI38AiJ_cptTl3RbzLyca3t-AAiH-Hh:RLxTVoX_IHF90KYey7xY_uWX92s=:eyJhcHBJZCI6ImQ4ZHJlOHcxcCIsImV4cGlyZUF0IjoxNzQxNDIzMzYyLCJwZXJtaXNzaW9uIjoidXNlciIsInJvb21OYW1lIjoiMTIzMTIzIiwidXNlcklkIjoiMTIzMTIzc2FkYXMifQ==";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AISdkManager.INSTANCE.init(this.getApplicationContext());
mRoomTokenEditText = findViewById(R.id.room_token_edit_text);
isPermissionOK();

new PermissionChecker(this).checkPermission();
findViewById(R.id.buttonToken1).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ class QnTrackAlDemo : Fragment() {
* @param audioToText 当前片段的结果文字数据
*/
override fun onAudioToText(audioToText: QNAudioToText) {
binding.tvText.text =
audioToText.bestTranscription.transcribedText ?: ""
binding.tvText.text = JsonUtils.toJson(audioToText)
}
})
} else {
Expand Down
55 changes: 21 additions & 34 deletions app/src/main/java/com/qiniu/droid/rtc/sample1v1ai/RecorderDemo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ import com.qiniu.droid.rtc.ai.core.util.MediaStoreUtils
import com.qiniu.droid.rtc.sample1v1ai.RoomActivity.getScreenHeight
import com.qiniu.droid.rtc.sample1v1ai.RoomActivity.getScreenWidth
import com.qiniu.droid.rtclocalrecord.QNRTCLocalRecordPlugin
import com.qiniu.droid.rtclocalrecord.QNRTCRecordPlugin
import com.qiniu.droid.rtclocalrecord.interfaces.QNLocalRecorderCallback
import com.qiniu.droid.rtclocalrecord.interfaces.QNScreenShareCallback
import com.qiniuavbox.avcapture.screen.ScreenRecordService
import com.qiniuavbox.avencoder.VideoEncodeParam

class RecorderDemo : Fragment() {

Expand All @@ -35,20 +32,12 @@ class RecorderDemo : Fragment() {
return v
}

companion object {
const val recordWidth = 720
val recordHeight =
recordWidth * (ScreenRecordService.screenHeight / ScreenRecordService.screenWidth)

init {
QNRTCRecordPlugin.initScreenCaptureService(recordWidth, recordHeight)
}
}

@SuppressLint("SetTextI18n")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

QNRTCLocalRecordPlugin.getInstance().setInterruptCallBack {
Toast.makeText(requireContext(),"被打断",Toast.LENGTH_LONG).show()
}
val btn = view.findViewById<Button>(R.id.recoder)

btn.setOnClickListener(View.OnClickListener {
Expand All @@ -58,18 +47,16 @@ class RecorderDemo : Fragment() {
} else {
Environment.getExternalStorageDirectory().absolutePath + "/A"
}
if (!btn.isSelected) {
QNRTCRecordPlugin.startMediaRecorder(
if (!btn.isSelected()) {
QNRTCLocalRecordPlugin.getInstance().startMediaRecorder(
client,
requireActivity(),
url,
System.currentTimeMillis().toString() + "",
VideoEncodeParam(
recordWidth,
recordHeight,
800 * 1000, 15
),

getScreenWidth(),
getScreenHeight(),
15,
1000 * 1000,
object : QNLocalRecorderCallback {
private var file = ""
/**
Expand Down Expand Up @@ -117,7 +104,7 @@ class RecorderDemo : Fragment() {
}
})
} else {
QNRTCRecordPlugin.stopMediaRecorder(client)
QNRTCLocalRecordPlugin.getInstance().stopMediaRecorder(requireContext(), client)
}
})

Expand All @@ -127,10 +114,10 @@ class RecorderDemo : Fragment() {
if (!btnShare.isSelected()) {
//创建共享参数
val config = QNCustomVideoTrackConfig(RoomActivity.TAG_SCREEN)
//.setVideoEncodeFormat(QNVideoFormat(720, 1280, 20))
// .setBitrate(1500)
//.setVideoEncodeFormat(QNVideoFormat(720, 1280, 20))
// .setBitrate(1500)
//创建屏幕共享轨道
QNRTCRecordPlugin.createRTCScreenShareTrack(
QNRTCLocalRecordPlugin.getInstance().createScreenShareTrack(
requireActivity(),
config,
object : QNScreenShareCallback {
Expand All @@ -142,22 +129,22 @@ class RecorderDemo : Fragment() {

override fun onError(p0: Int, p1: String?) {
}
}, ArrayList<QNLocalTrack>().apply { add(mScreenShareTrack!!) })
btnShare.isSelected = true
btnShare.text = "取消共享"
}, ArrayList<QNLocalTrack>().apply { add(mScreenShareTrack!!) } )
btnShare.setSelected(true)
btnShare.setText("取消共享")
}

override fun onError(code: Int, msg: String) {
Log.d("QNRTCRecordPlugin", "屏幕共享轨道场景创建失败")
Log.d(RoomActivity.TAG, "屏幕共享轨道场景创建失败")
}
})
} else {
QNRTCRecordPlugin.releaseRTCScreenShareTrack()
QNRTCLocalRecordPlugin.getInstance().releaseScreenShareTrack(requireContext())
client.unpublish(mScreenShareTrack)
btnShare.isSelected = false
btnShare.text = "屏幕共享"
btnShare.setSelected(false)
btnShare.setText("屏幕共享")
}
})

}

}
13 changes: 13 additions & 0 deletions app/src/main/java/com/qiniu/droid/rtc/sample1v1ai/TokenUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,17 @@

public class TokenUtils {

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

static String appKey = "QxZugR8TAhI38AiJ_cptTl3RbzLyca3t-AAiH-Hh";
static String appId = "testApp";
static String appSecretKey = "4yv8mE9kFeoE31PVlIjWvi3nfTytwT0JiAxWjCDa";

public static String resetToken() {
return "QD QxZugR8TAhI38AiJ_cptTl3RbzLyca3t-AAiH-Hh:jzx6H3eRaBbh-bYQfPS9wgpc_D4=:dGVzdEFwcDoxNjU2MDUxOTQy";
}

public static String signUrlToToken(String url) {
return Auth.create(appKey, appSecretKey).sign(url);// "${appKey}:${sha1}"
}
}
Loading

0 comments on commit 158a321

Please sign in to comment.