/*private bool isInitialized; * private string lastSent;*/ private async Task <string> TryGetMessageAsync(string request) { try { return((await apiAi.TextRequestAsync(request)).Result.Fulfillment.Speech); } catch { return(null); } }
public async void Run(IBackgroundTaskInstance taskInstance) { serviceDeferral = taskInstance.GetDeferral(); taskInstance.Canceled += OnTaskCanceled; var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails; if (triggerDetails != null) { var config = new AIConfiguration("6bcfd8fcf822482e935475852b97c02d", SupportedLanguage.English); apiAi = new ApiAi(config); apiAi.DataService.PersistSessionId(); try { voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails); voiceServiceConnection.VoiceCommandCompleted += VoiceCommandCompleted; var voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync(); var recognizedText = voiceCommand.SpeechRecognitionResult?.Text; switch (voiceCommand.CommandName) { case "Open": //개점 { var aiResponse = await apiAi.TextRequestAsync(recognizedText); //await apiAi.LaunchAppInForegroundAsync(voiceServiceConnection, aiResponse); var processingMessage = new VoiceCommandUserMessage { DisplayMessage = "Starting POS...", SpokenMessage = "Starting POS..." }; var resp = VoiceCommandResponse.CreateResponse(processingMessage); await voiceServiceConnection.ReportSuccessAsync(resp); POS_main.start = true; } break; case "Close": //마감 { var aiResponse = await apiAi.TextRequestAsync(recognizedText); var processingMessage = new VoiceCommandUserMessage { DisplayMessage = "Program The End...", SpokenMessage = "Program The End..." }; var resp = VoiceCommandResponse.CreateResponse(processingMessage); await voiceServiceConnection.ReportSuccessAsync(resp); /*시스템 종료 함수*/ SetFinishing(); break; } case "SaleStatus": //매출현황 { } break; case "SaleSearch": //판매조회 { } break; case "PayCheck": //아르바이트 시간 및 급여 확인 { } break; default: if (!string.IsNullOrEmpty(recognizedText)) { var aiResponse = await apiAi.TextRequestAsync(recognizedText); if (aiResponse != null) { await apiAi.SendResponseToCortanaAsync(voiceServiceConnection, aiResponse); } } else { await SendResponse("Can't recognize"); } break; } } catch (Exception e) { var message = e.ToString(); Debug.WriteLine(message); } finally { serviceDeferral?.Complete(); } } }
public async void Run(IBackgroundTaskInstance taskInstance) { serviceDeferral = taskInstance.GetDeferral(); taskInstance.Canceled += OnTaskCanceled; var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails; if (triggerDetails != null) { var config = new AIConfiguration("cb9693af-85ce-4fbf-844a-5563722fc27f", "40048a5740a1455c9737342154e86946", SupportedLanguage.English); apiAi = new ApiAi(config); apiAi.DataService.PersistSessionId(); try { voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails); voiceServiceConnection.VoiceCommandCompleted += VoiceCommandCompleted; var voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync(); var recognizedText = voiceCommand.SpeechRecognitionResult?.Text; switch (voiceCommand.CommandName) { case "type": { var aiResponse = await apiAi.TextRequestAsync(recognizedText); await apiAi.LaunchAppInForegroundAsync(voiceServiceConnection, aiResponse); } break; case "unknown": { if (!string.IsNullOrEmpty(recognizedText)) { var aiResponse = await apiAi.TextRequestAsync(recognizedText); if (aiResponse != null) { await apiAi.SendResponseToCortanaAsync(voiceServiceConnection, aiResponse); } } } break; case "greetings": { var aiResponse = await apiAi.TextRequestAsync(recognizedText); var repeatMessage = new VoiceCommandUserMessage { DisplayMessage = "Repeat please", SpokenMessage = "Repeat please" }; var processingMessage = new VoiceCommandUserMessage { DisplayMessage = aiResponse?.Result?.Fulfillment?.Speech ?? "Pizza", SpokenMessage = "" }; var resp = VoiceCommandResponse.CreateResponseForPrompt(processingMessage, repeatMessage); await voiceServiceConnection.ReportSuccessAsync(resp); break; } default: if (!string.IsNullOrEmpty(recognizedText)) { var aiResponse = await apiAi.TextRequestAsync(recognizedText); if (aiResponse != null) { await apiAi.SendResponseToCortanaAsync(voiceServiceConnection, aiResponse); } } else { await SendResponse("Can't recognize"); } break; } } catch (Exception e) { var message = e.ToString(); Debug.WriteLine(message); } finally { serviceDeferral?.Complete(); } } }