javascriptspeech-recognitionazure-communication-services

TypeError: Cannot read properties of undefined (reading 'kind')


I am trying to create a simple IVR using Microsoft Azure Communication Services. I have created a function to answer an incoming call, and a function to handle the event during the call such as playing an audio, getting input from the user, etc.

When a call is answered, an audio file will be played. This part of my functions works fine. The next part is that the user/caller will hear another audio file and will be asked to answer a question. I used the Call Automation package and speech recognition, but I got the following error when getting the inputs from the user:

"Error processing event: TypeError: Cannot read properties of undefined (reading 'kind')".

The function is as follows:

    if (eventType === 'Microsoft.Communication.CallConnected') {
            const callConnectionId = eventData.callConnectionId;

            // Play an audio 
            const playSource = { url: "...", kind: "fileSource" };
            await callAutomationClient.getCallConnection(callConnectionId).getCallMedia().playToAll([playSource]);

            // another audio source
            const playSource = { URL: "...", kind: "fileSource" };

            const recognizeOptions = {   
                playPrompt: playSource, 
                initialSilenceTimeoutInSeconds: 10, 
                interruptPrompt: true, 
                operationContext: "OpenQuestionSpeech", 
                kind: "callMediaRecognizeSpeechOptions"
            }; 

            await callAutomationClient.getCallConnection(callConnectionId).getCallMedia().startRecognizing(recognizeOptions); 
};

There seems to be a problem with kind: "callMediaRecognizeSpeechOptions" in the last line of the recognizeOptions typescript. I followed the instructions in Gather user input with Recognize action and CallMediaRecognizeSpeechOptions interface, but still got this error.

I would appreciate any help and suggestions.


Solution

  • First of all, there is a missing comma operator in the line:

    const playSource = { url: "..." kind: "fileSource" };
    

    Also looking at the documentation, it appears that the startRecognizing function accepts two parameters targetParticipant and recognizeOptions, but you are passing recognizeOptions in place of targetParticipant. Try fixing this.