|
|
@@ -413,7 +413,9 @@
|
|
|
let sdk = null
|
|
|
let sttManager = null
|
|
|
let rtmManager = null
|
|
|
+ let rtcManager = null
|
|
|
let isSdkInitialized = false
|
|
|
+ let isRtcManagerJoined = false
|
|
|
|
|
|
// 添加测试日志
|
|
|
function addTestLog(message, type = "info") {
|
|
|
@@ -529,6 +531,7 @@
|
|
|
// 创建管理器
|
|
|
rtmManager = sdk.createRtmManager()
|
|
|
sttManager = sdk.createSttManager(rtmManager)
|
|
|
+ rtcManager = sdk.createRtcManager()
|
|
|
|
|
|
// 监听RTM事件
|
|
|
rtmManager.on("sttDataChanged", (data) => {
|
|
|
@@ -536,12 +539,12 @@
|
|
|
})
|
|
|
|
|
|
// 监听RTC文本流事件
|
|
|
- rtmManager.on("textstreamReceived", (textstream) => {
|
|
|
+ rtcManager.on("textstreamReceived", (textstream) => {
|
|
|
addTestLog("收到文本流数据: " + JSON.stringify(textstream))
|
|
|
updateRealtimeDisplay(textstream)
|
|
|
})
|
|
|
|
|
|
- addTestLog("STT和RTM管理器创建成功", "success")
|
|
|
+ addTestLog("STT、RTM和RTC管理器创建成功", "success")
|
|
|
document.getElementById("transcribeBtn").disabled = false
|
|
|
document.getElementById("cleanupBtn").disabled = false
|
|
|
})
|
|
|
@@ -555,8 +558,8 @@
|
|
|
|
|
|
// 测试转录功能
|
|
|
function testTranscription() {
|
|
|
- if (!sttManager) {
|
|
|
- addTestLog("STT管理器未初始化", "error")
|
|
|
+ if (!sttManager || !rtcManager) {
|
|
|
+ addTestLog("STT管理器或RTC管理器未初始化", "error")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
@@ -567,16 +570,39 @@
|
|
|
|
|
|
// 生成随机用户ID
|
|
|
const genRandomUserId = () => Math.floor(Math.random() * 1000000)
|
|
|
+ const userId = genRandomUserId()
|
|
|
|
|
|
sttManager
|
|
|
.init({
|
|
|
- userId: genRandomUserId(),
|
|
|
+ userId: userId,
|
|
|
channel: channel,
|
|
|
userName: userName,
|
|
|
})
|
|
|
.then(() => {
|
|
|
addTestLog("STT管理器初始化成功", "success")
|
|
|
|
|
|
+ // 加入RTC频道
|
|
|
+ return rtcManager.join({
|
|
|
+ channel: channel,
|
|
|
+ userId: userId,
|
|
|
+ })
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ addTestLog("RTC频道加入成功", "success")
|
|
|
+ isRtcManagerJoined = true
|
|
|
+
|
|
|
+ // 创建音视频轨道
|
|
|
+ return rtcManager.createTracks()
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ addTestLog("音视频轨道创建成功", "success")
|
|
|
+
|
|
|
+ // 发布音视频流
|
|
|
+ return rtcManager.publish()
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ addTestLog("音视频流发布成功", "success")
|
|
|
+
|
|
|
// 开始转录
|
|
|
return sttManager.startTranscription({
|
|
|
languages: [{ source: "zh-CN" }],
|
|
|
@@ -585,7 +611,7 @@
|
|
|
.then(() => {
|
|
|
addTestLog("转录功能启动成功", "success")
|
|
|
|
|
|
- // 模拟5秒后停止转录
|
|
|
+ // 模拟10秒后停止转录
|
|
|
setTimeout(() => {
|
|
|
if (sttManager) {
|
|
|
sttManager
|
|
|
@@ -597,7 +623,7 @@
|
|
|
addTestLog("停止转录失败: " + error, "error")
|
|
|
})
|
|
|
}
|
|
|
- }, 5000)
|
|
|
+ }, 10000)
|
|
|
})
|
|
|
.catch((error) => {
|
|
|
addTestLog("转录功能测试失败: " + error, "error")
|
|
|
@@ -641,6 +667,19 @@
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ if (rtcManager) {
|
|
|
+ rtcManager
|
|
|
+ .destroy()
|
|
|
+ .then(() => {
|
|
|
+ addTestLog("RTC管理器销毁成功", "success")
|
|
|
+ rtcManager = null
|
|
|
+ isRtcManagerJoined = false
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ addTestLog("RTC管理器销毁失败: " + error, "error")
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
if (sdk) {
|
|
|
sdk
|
|
|
.destroy()
|