/// <summary> /// Gets text from an audio stream. /// </summary> /// <param name="audiostream"></param> /// <returns>Transcribed text. </returns> public async Task <string> GetTextFromAudioAsync(Stream audiostream) { var text = await BingSpeech.GetTextFromAudioAsync(audiostream); Debug.WriteLine(text); return(text); }
private Task OnRecordCompleted(RecordOutcomeEvent recordOutcomeEvent) { var id = Guid.NewGuid().ToString(); recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase> { GetPromptForText(IvrOptions.Ending), new Hangup { OperationId = id } }; var conversationId = recordOutcomeEvent.ConversationResult.Id; var recordedContent = recordOutcomeEvent.RecordedContent.Result; BingSpeech bs = new BingSpeech( async t => { this._callStateMap[conversationId].SpeechToTextPhrase = t; // The below is not always guaranteed var url = "https://skype.botframework.com"; // create a channel account for user var userAccount = new ChannelAccount(caller.Identity, caller.DisplayName); // create a channel account for bot var botAccount = new ChannelAccount(callee.Identity, callee.DisplayName); // authentication var account = new MicrosoftAppCredentials(ConfigurationManager.AppSettings["MicrosoftAppId"].ToString(), ConfigurationManager.AppSettings["MicrosoftAppPassword"].ToString()); var connector = new ConnectorClient(new Uri(url), account); // This is required for Microsoft App Credentials to trust the outgoing message // This is automatically done for incoming messages, since we are initiating a proactive message // the service url should be trustable MicrosoftAppCredentials.TrustServiceUrl(url, DateTime.Now.AddDays(7)); // Create a direct line connection with the user for proactive communication var conversation = await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount); IMessageActivity message = Activity.CreateMessageActivity(); message.From = botAccount; message.Recipient = userAccount; message.Conversation = new ConversationAccount(id: conversation.Id); // send the message, remember the call is dropped by now. You can design your in a way // that you can seek confirmation from the user on the converted text message.Text = string.Format("Your comment has been recorded. Thanks for calling: {0}, Complaint Id: {1}", t, conversationId); message.Locale = "en-us"; await connector.Conversations.SendToConversationAsync((Activity)message); this._callStateMap.Remove(conversationId); }, t => Console.WriteLine("Bing Speech to Text failed with error: " + t) ); bs.CreateDataRecoClient(); bs.SendAudioHelper(recordedContent); recordOutcomeEvent.ResultingWorkflow.Links = null; //_callStateMap.Remove(recordOutcomeEvent.ConversationResult.Id); return(Task.FromResult(true)); }
private async Task OnRecordCompleted(RecordOutcomeEvent recordOutcomeEvent) { var id = Guid.NewGuid().ToString(); recordOutcomeEvent.ResultingWorkflow.Actions = new List <ActionBase> { GetPromptForText(Message_Ending), new Hangup { OperationId = id } }; // Convert the audio to text if (recordOutcomeEvent.RecordOutcome.Outcome == Outcome.Success) { var record = await recordOutcomeEvent.RecordedContent; string sst = await BingSpeech.GetTextFromAudioAsync(record); await SendSTTResultToUser($"We detected the following audio: {sst}"); } recordOutcomeEvent.ResultingWorkflow.Links = null; _callStateMap.Remove(recordOutcomeEvent.ConversationResult.Id); }