我正在尝试接听电话并将其传输到认知服务。我该怎么做?
我试过:在Azure中设置电话号码,制作Azure事件网格,并设置一个webhook将事件发送到我的应用程序。但是,我似乎无法从接收到的对象中获得流。代码:
[AllowAnonymous]
[HttpPost]
public async Task<IActionResult> IncomingCall([FromBody] EventGridEvent[] events)
{
int eventCount = 0;
foreach (var eventGridEvent in events)
{
try
{
switch (eventGridEvent.EventType)
{
case SystemEventNames.EventGridSubscriptionValidation:
{
var eventData = eventGridEvent.Data.ToObjectFromJson<SubscriptionValidationEventData>();
var responseData = new SubscriptionValidationResponse
{ ValidationResponse = eventData.ValidationCode };
if (responseData.ValidationResponse != null)
{ return Ok(responseData);}
}
break;
case "Microsoft.Communication.IncomingCall":
var _client = new CallAutomationClient("<ACS connection string>");
var eventData2 = eventGridEvent.Data.ToObjectFromJson<AcsIncomingCallEventData>();
string incomingCallContext = eventData2.IncomingCallContext;
string serverCallId = eventData2.ServerCallId;
var answerCallOptions = new AnswerCallOptions(incomingCallContext, new Uri("wss://... my url here}"));
answerCallOptions.OperationContext = "";
var call = await _client.AnswerCallAsync(answerCallOptions);
// How to get the stream from the call?
// then stream into Azure CLU
// some constants
var speechConfig = SpeechConfig.FromSubscription(speechKey, speechRegion);
speechConfig.SpeechRecognitionLanguage = "en-US";
speechConfig.SetProperty(PropertyId.Speech_SegmentationSilenceTimeoutMs, "2000");
using AudioConfig audioConfig = AudioConfig.FromStreamInput(audioStream);
using (var intentRecognizer = new IntentRecognizer(speechConfig, audioConfig))
我试过这个。但是当我得到一些文本时,我如何将这些文本流到CLU(IntentRecognizer)中?
var callAutomationClient = new CallAutomationClient("<ACS connection string>");
var answerCallOptions = new AnswerCallOptions("<Incoming call context once call is connected>", new Uri("<https://sample-callback-uri>"))
{
AzureCognitiveServicesEndpointUrl = new Uri("https://sample-cognitive-service-resource.cognitiveservices.azure.com/") // for Speech-To-Text (choices)
};
var answerCallResult = await callAutomationClient.AnswerCallAsync(answerCallOptions);
1条答案
按热度按时间q7solyqu1#
在代码中,您已经设置了EventGrid订阅并正在接收事件。若要处理传入呼叫事件,可以使用以下代码
call.AudioStream
是包含来自电话呼叫的音频的流。