在解决了这个问题中的错误之后,我遇到了另一个错误,如下所示:
Request not allowed when Cognitive Service Configuration not set during call setup.
我正在尝试使用 Azure 通信服务和语音资源构建一个简单的 IVR。我按照将 Azure 通信服务与 Azure AI 服务连接中的说明手动将 Azure 通信服务与认知服务连接起来,但如何在呼叫设置中配置认知服务?有没有内置函数可以在通话过程中设置这样的配置?
这里,您需要正确配置与语音服务提供商的azure通信服务,如下所示。
将此“认知服务用户”角色分配给您的语音服务。检查此SO链接以获取更多理解
// Define Cognitive Services configuration
const cognitiveServicesConfig = {
subscriptionKey: "your-cognitive-services-subscription-key",
endpoint: "your-cognitive-services-endpoint-url"
};
app.get('/', async (req, res) => {
try {
if (eventType === 'Microsoft.Communication.CallConnected') {
const callConnectionId = eventData.callConnectionId;
console.log(`Call connected with callConnectionId: ${callConnectionId}`);
// Play an initial audio
const initialPlaySource = { url: "...", kind: "fileSource" };
console.log('Playing initial audio to all participants...');
await callAutomationClient.getCallConnection(callConnectionId).getCallMedia().playToAll([initialPlaySource]);
console.log('Initial audio played.');
// Define another audio source for the speech recognition prompt
const promptPlaySource = { url: "...", kind: "fileSource" };
console.log('Defined prompt audio source for speech recognition.');
// Define the target participant for the recognition (if needed, modify accordingly)
const targetParticipant = { identifier: { communicationUser: { id: "participant-id" } } };
console.log(`Target participant for recognition: ${targetParticipant.identifier.communicationUser.id}`);
// Configure the speech recognition options with Cognitive Services
const recognizeOptions = {
playPrompt: promptPlaySource,
initialSilenceTimeoutInSeconds: 10,
interruptPrompt: true,
operationContext: "OpenQuestionSpeech",
kind: "callMediaRecognizeSpeechOptions",
cognitiveServicesConfig: cognitiveServicesConfig // Add the Cognitive Services configuration here
};
console.log('Configured speech recognition options.');
// Start the speech recognition process
console.log('Starting speech recognition...');
cognitiveServicesConfig
对象是使用认知服务/语音服务资源的订阅密钥和端点 URL 创建的。通过上述配置,您可以访问将语音服务与通信服务/呼叫设置连接。