|
|
@@ -9,12 +9,6 @@ import type {
|
|
|
ILanguageItem,
|
|
|
} from '../types'
|
|
|
|
|
|
-// STT API接口定义
|
|
|
-interface ApiSTTResponse {
|
|
|
- tokenName?: string
|
|
|
- taskId?: string
|
|
|
-}
|
|
|
-
|
|
|
interface ApiSTTStartOptions {
|
|
|
uid: string | number
|
|
|
channel: string
|
|
|
@@ -363,19 +357,25 @@ export class SttManagerAdapter extends AGEventEmitter<SttEventMap> implements IS
|
|
|
private async _apiSTTAcquireToken(options: {
|
|
|
channel: string
|
|
|
uid: string | number
|
|
|
- }): Promise<ApiSTTResponse> {
|
|
|
- const { channel } = options
|
|
|
+ }): Promise<{ tokenName: string }> {
|
|
|
+ const { channel, uid } = options
|
|
|
const data: any = {
|
|
|
instanceId: channel,
|
|
|
}
|
|
|
|
|
|
+ // 这里可以添加测试环境的特殊处理逻辑
|
|
|
+ // if (this._mode === 'test') {
|
|
|
+ // data.testIp = "218.205.37.49"
|
|
|
+ // data.testPort = 4447
|
|
|
+ // }
|
|
|
+
|
|
|
const url = `${this._gatewayAddress}/v1/projects/${this._appId}/rtsc/speech-to-text/builderTokens`
|
|
|
|
|
|
const response = await fetch(url, {
|
|
|
method: 'POST',
|
|
|
headers: {
|
|
|
'Content-Type': 'application/json',
|
|
|
- Authorization: await this._genAuthorization(options),
|
|
|
+ Authorization: await this._genBasicAuthorization({ uid, channel }),
|
|
|
},
|
|
|
body: JSON.stringify(data),
|
|
|
})
|
|
|
@@ -383,7 +383,8 @@ export class SttManagerAdapter extends AGEventEmitter<SttEventMap> implements IS
|
|
|
if (response.status === 200) {
|
|
|
return await response.json()
|
|
|
} else {
|
|
|
- throw new Error(`API call failed with status: ${response.status}`)
|
|
|
+ console.error('API STT Acquire Token failed:', response.status, response)
|
|
|
+ throw new Error(`API STT Acquire Token failed with status: ${response.status}`)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -495,16 +496,15 @@ export class SttManagerAdapter extends AGEventEmitter<SttEventMap> implements IS
|
|
|
uid: string | number
|
|
|
channel: string
|
|
|
}): Promise<string> {
|
|
|
- // 在实际实现中,这里应该调用真实的token生成逻辑
|
|
|
- // 这里简化实现,返回一个基本的认证头
|
|
|
- const token = await this._apiGetAgoraToken(config)
|
|
|
- return `agora token="${token}"`
|
|
|
+ // 使用基础的Agora token(与主应用保持一致)
|
|
|
+ return await this._genBasicAuthorization(config)
|
|
|
}
|
|
|
|
|
|
- private async _apiGetAgoraToken(config: {
|
|
|
+ private async _genBasicAuthorization(config: {
|
|
|
uid: string | number
|
|
|
channel: string
|
|
|
- }): Promise<string | null> {
|
|
|
+ }): Promise<string> {
|
|
|
+ // 使用基础的Agora token生成逻辑
|
|
|
const { uid, channel } = config
|
|
|
const url = `${this._baseUrl}/v2/token/generate`
|
|
|
|
|
|
@@ -528,9 +528,10 @@ export class SttManagerAdapter extends AGEventEmitter<SttEventMap> implements IS
|
|
|
|
|
|
if (response.ok) {
|
|
|
const result = await response.json()
|
|
|
- return result?.data?.token || null
|
|
|
+ const token = result?.data?.token || ''
|
|
|
+ return `agora token="${token}"`
|
|
|
}
|
|
|
|
|
|
- return null
|
|
|
+ return ''
|
|
|
}
|
|
|
}
|