你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
在客户端上显示通话听录状态
注意
通话听录状态仅在 Teams 会议中可用。 目前,不支持 Azure 通信服务到 Azure 通信服务通话的通话听录状态。
使用通话听录时,可能需要让用户知道正在听录通话。 操作方法如下。
先决条件
- 具有活动订阅的 Azure 帐户。 免费创建帐户。
- 已部署的通信服务资源。 创建通信服务资源。
- 用于启用通话客户端的用户访问令牌。 有关详细信息,请参阅创建和管理访问令牌。
- 可选:完成快速入门向应用程序添加语音呼叫
安装 SDK
找到项目级别的 build.gradle 文件,并将 mavenCentral()
添加到 buildscript
和 allprojects
下的存储库列表中:
buildscript {
repositories {
...
mavenCentral()
...
}
}
allprojects {
repositories {
...
mavenCentral()
...
}
}
然后,在模块级别的 build.gradle 文件中,将以下行添加到 dependencies
部分:
dependencies {
...
implementation 'com.azure.android:azure-communication-calling:1.0.0'
...
}
初始化所需的对象
若要创建 CallAgent
实例,必须对 CallClient
实例调用 createCallAgent
方法。 此调用异步返回 CallAgent
实例对象。
createCallAgent
方法采用 CommunicationUserCredential
作为参数来封装访问令牌。
若要访问 DeviceManager
,必须先创建 callAgent
实例。 然后,可以使用 CallClient.getDeviceManager
方法获取 DeviceManager
。
String userToken = '<user token>';
CallClient callClient = new CallClient();
CommunicationTokenCredential tokenCredential = new CommunicationTokenCredential(userToken);
android.content.Context appContext = this.getApplicationContext(); // From within an activity, for instance
CallAgent callAgent = callClient.createCallAgent(appContext, tokenCredential).get();
DeviceManager deviceManager = callClient.getDeviceManager(appContext).get();
若要为主叫方设置显示名称,请使用以下替代方法:
String userToken = '<user token>';
CallClient callClient = new CallClient();
CommunicationTokenCredential tokenCredential = new CommunicationTokenCredential(userToken);
android.content.Context appContext = this.getApplicationContext(); // From within an activity, for instance
CallAgentOptions callAgentOptions = new CallAgentOptions();
callAgentOptions.setDisplayName("Alice Bob");
DeviceManager deviceManager = callClient.getDeviceManager(appContext).get();
CallAgent callAgent = callClient.createCallAgent(appContext, tokenCredential, callAgentOptions).get();
警告
在 Azure 通信服务呼叫 Android SDK 的 1.1.0 版和 beta 版 1.1.0-beta.1 之前,isTranscriptionActive
和 addOnIsTranscriptionActiveChangedListener
是 Call
对象的一部分。 对于新的 Beta 版本,这些 API 已作为 Call
的扩展功能移动,如下所述。
通话听录是核心 Call
对象的扩展功能。 首先,需要获取听录功能对象:
TranscriptionCallFeature callTranscriptionFeature = call.feature(Features.TRANSCRIPTION);
然后,若要检查是否正在停录通话,请检查 callTranscriptionFeature
的 isTranscriptionActive
属性。 它将返回 boolean
。
boolean isTranscriptionActive = callTranscriptionFeature.isTranscriptionActive();
还可以订阅听录中的更改:
private void handleCallOnIsTranscriptionChanged(PropertyChangedEvent args) {
boolean isTranscriptionActive = callTranscriptionFeature.isTranscriptionActive();
}
callTranscriptionFeature.addOnIsTranscriptionActiveChangedListener(handleCallOnIsTranscriptionChanged);
设置系统
创建 Xcode 项目
在 Xcode 中,创建新的 iOS 项目,并选择“单视图应用”模板。 本快速入门使用 SwiftUI 框架,因此应将“语言”设置为“Swift”,并将“接口”设置为“SwiftUI”。
在此快速入门过程中,无需创建测试。 请随意清除“包括测试”复选框。
使用 CocoaPods 安装包和依赖项
为应用程序创建 Podfile,如此示例所示:
platform :ios, '13.0' use_frameworks! target 'AzureCommunicationCallingSample' do pod 'AzureCommunicationCalling', '~> 1.0.0' end
运行
pod install
。使用 Xcode 打开
.xcworkspace
。
请求访问麦克风
若要访问设备的麦克风,需要使用 NSMicrophoneUsageDescription
更新应用的信息属性列表。 将关联的值设置为要包含在对话框中的字符串,系统使用该对话框向用户请求访问权限。
右键单击项目树的 Info.plist 条目,然后选择“打开为...”>“源代码”。 将以下代码行添加到顶层 <dict>
节,然后保存文件。
<key>NSMicrophoneUsageDescription</key>
<string>Need microphone access for VOIP calling.</string>
设置应用框架
打开项目的 ContentView.swift 文件。 将 import
声明添加到文件顶部以导入 AzureCommunicationCalling
库。 此外,导入 AVFoundation
。 你将需要用它来处理代码中的音频权限请求。
import AzureCommunicationCalling
import AVFoundation
初始化 CallAgent
若要从 CallClient
创建 CallAgent
实例,必须使用 callClient.createCallAgent
方法,该方法在初始化后异步返回 CallAgent
对象。
若要创建通话客户端,请传递 CommunicationTokenCredential
对象:
import AzureCommunication
let tokenString = "token_string"
var userCredential: CommunicationTokenCredential?
do {
let options = CommunicationTokenRefreshOptions(initialToken: token, refreshProactively: true, tokenRefresher: self.fetchTokenSync)
userCredential = try CommunicationTokenCredential(withOptions: options)
} catch {
updates("Couldn't created Credential object", false)
initializationDispatchGroup!.leave()
return
}
// tokenProvider needs to be implemented by Contoso, which fetches a new token
public func fetchTokenSync(then onCompletion: TokenRefreshOnCompletion) {
let newToken = self.tokenProvider!.fetchNewToken()
onCompletion(newToken, nil)
}
将创建的 CommunicationTokenCredential
对象传递给 CallClient
并设置显示名称:
self.callClient = CallClient()
let callAgentOptions = CallAgentOptions()
options.displayName = " iOS Azure Communication Services User"
self.callClient!.createCallAgent(userCredential: userCredential!,
options: callAgentOptions) { (callAgent, error) in
if error == nil {
print("Create agent succeeded")
self.callAgent = callAgent
} else {
print("Create agent failed")
}
})
警告
1.1.0 和 1.1.0-beta.1(beta 版)之前版本的 Azure 通信服务呼叫 iOS SDK 使用 isTranscriptionActive
作为 Call
对象的一部分,并且 didChangeTranscriptionState
属于 CallDelegate
委托的一部分。 对于新的 Beta 版本,这些 API 已作为 Call
的扩展功能移动,如下所述。
通话听录是核心 Call
对象的扩展功能。 首先,需要获取听录功能对象:
let callTranscriptionFeature = call.feature(Features.transcription)
然后,若要确认是否正在听录通话,请检查 callTranscriptionFeature
的 isTranscriptionActive
属性。 它将返回 Bool
。
let isTranscriptionActive = callTranscriptionFeature.isTranscriptionActive;
还可以通过使用事件 TranscriptionCallFeatureDelegate
在类层级实现 didChangeTranscriptionState
委托,以订阅听录更改:
callTranscriptionFeature.delegate = self
// didChangeTranscriptionState is a member of TranscriptionCallFeatureDelegate
public func transcriptionCallFeature(_ transcriptionCallFeature: TranscriptionCallFeature, didChangeTranscriptionState args: PropertyChangedEventArgs) {
let isTranscriptionActive = callTranscriptionFeature.isTranscriptionActive
}
设置系统
创建 Visual Studio 项目
对于 UWP 应用,请在 Visual Studio 2022 中创建新的“空白应用(通用 Windows)”项目。 输入项目名称后,可随意选择任何版本高于 10.0.17763.0 的 Windows SDK。
对于 WinUI 3 应用,请使用“已打包空白应用(桌面中的 WinUI 3)”模板创建新项目,以设置单页 WinUI 3 应用。 需要 Windows App SDK 版本 1.3 或更高版本。
使用 NuGet 包管理器安装包和依赖项
可通过 NuGet 包公开提供通话 SDK API 和库。
以下步骤举例说明了如何查找、下载和安装通话 SDK NuGet 包:
- 选择“工具”>“NuGet 包管理器”>“管理解决方案的 NuGet 包”,打开 NuGet 包管理器。
- 选择“浏览”,然后在搜索框中输入
Azure.Communication.Calling.WindowsClient
。 - 确保已选中“包括预发行版”复选框。
- 选择
Azure.Communication.Calling.WindowsClient
包,然后选择Azure.Communication.Calling.WindowsClient
1.4.0-beta.1 或更高版本。 - 选中与右侧选项卡上的 Azure 通信服务项目对应的复选框。
- 选择“安装”按钮。
通话听录是核心 Call
对象的扩展功能。 首先,需要获取听录功能对象:
TranscriptionCallFeature transcriptionFeature = call.Features.Transcription;
然后,若要检查是否正在停录通话,请检查 transcriptionFeature
的 IsTranscriptionActive
属性。 它将返回 boolean
。
boolean isTranscriptionActive = transcriptionFeature.isTranscriptionActive;
还可以订阅听录中的更改:
private async void Call__OnIsTranscriptionActiveChanged(object sender, PropertyChangedEventArgs args)
boolean isTranscriptionActive = transcriptionFeature.IsTranscriptionActive();
}
transcriptionFeature.IsTranscriptionActiveChanged += Call__OnIsTranscriptionActiveChanged;
后续步骤
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈