public void DifferentAgentsTest() { var query = "I want pizza"; { var dataService = CreateDataService(); var request = new AIRequest(query); var response = dataService.Request(request); Assert.IsNotNull(response.Result); Assert.AreEqual("pizza", response.Result.Action); } { var config = new AIConfiguration(SUBSCRIPTION_KEY, "968235e8e4954cf0bb0dc07736725ecd", SupportedLanguage.English); var dataService = new AIDataService(config); var request = new AIRequest(query); var response = dataService.Request(request); Assert.IsNotNull(response.Result); Assert.IsTrue(string.IsNullOrEmpty(response.Result.Action)); } }
static void Main(string[] args) { var config = new AIConfiguration(SUBSCRIPTION_KEY, ACCESS_TOKEN, SupportedLanguage.English); var apiAi = new ApiAi(config); string rl = ""; while (rl == "") { var sw = Stopwatch.StartNew(); var response = apiAi.TextRequest("hello"); sw.Stop(); Console.WriteLine("api sync answer: {0}, time: {1} ms", response.Result.Action, sw.ElapsedMilliseconds.ToString()); sw = Stopwatch.StartNew(); apiAi.TextRequestStart("hello"); System.Threading.Thread.Sleep(250); response = apiAi.TextRequestFinish(); sw.Stop(); Console.WriteLine("api async answer: {0}, time: {1} ms", response.Result.Action, sw.ElapsedMilliseconds.ToString()); rl = Console.ReadLine(); } }
public AIDataService(AIConfiguration config) { this.config = config; sessionId = Guid.NewGuid().ToString(); httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new HttpCredentialsHeaderValue("Bearer", config.ClientAccessToken); httpClient.DefaultRequestHeaders.Accept.Add(new HttpMediaTypeWithQualityHeaderValue("application/json")); httpClient.DefaultRequestHeaders.Append("ocp-apim-subscription-key", config.SubscriptionKey); }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { Microsoft.ApplicationInsights.WindowsAppInitializer.InitializeAsync( Microsoft.ApplicationInsights.WindowsCollectors.Metadata | Microsoft.ApplicationInsights.WindowsCollectors.Session); InitializeComponent(); Suspending += OnSuspending; Resuming += OnResuming; var config = new AIConfiguration("cb9693af-85ce-4fbf-844a-5563722fc27f", "40048a5740a1455c9737342154e86946", SupportedLanguage.English); AIService = AIService.CreateService(config); }
public override void ViewDidLoad() { try { aiConfig = new AIConfiguration("135f1908-3d38-4954-83f4-d128948708b2", "a8f248a646ad49d3aa8d5f3ee017009a", SupportedLanguage.PortugueseBrazil); aiService = AIService.CreateService(aiConfig); this.StartListening(); } catch (Exception ex) { throw ex; } base.ViewDidLoad(); }
public SystemRecognitionService(AIConfiguration config) { this.config = config; dataService = new AIDataService(config); }
private void InitializeService(LanguageConfig conf) { var lang = SupportedLanguage.FromLanguageTag(conf.LanguageCode); var config = new AIConfiguration("62f2522a-7404-4c28-b9ac-097ca5d8b32d", conf.AccessToken, lang); //TODO: Option for verbose logging. Remove this line in production. config.DebugLog = true; if (aiService != null) { aiService.Cancel(); } aiService = AIService.CreateService(config); aiService.OnResult += AiService_OnResult; aiService.OnError += AiService_OnError; aiService.ListeningStarted += AiService_ListeningStarted; aiService.ListeningFinished += AiService_ListeningFinished; aiService.AudioLevelChanged += AiService_AudioLevelChanged; }
public static AIService CreateService(AIConfiguration config) { return new SystemRecognitionService(config); }
public AIDataService(AIConfiguration config) { this.config = config; sessionId = Guid.NewGuid().ToString(); }
public static AIService CreateService(AIConfiguration config) { return(new SystemRecognitionService(config)); }
protected AIService(AIConfiguration config) { this.config = config; DataService = new AIDataService(config); }
private AIDataService CreateDataService() { var config = new AIConfiguration(SUBSCRIPTION_KEY, ACCESS_TOKEN, SupportedLanguage.English); var dataService = new AIDataService(config); return dataService; }
// Use this for initialization IEnumerator Start() { // make sure the recordingtext is off RecordingText.SetActive (false); // Init MoveCamera location MoveCamera moveCamera = GetComponent<MoveCamera>(); moveCamera.UpdateLocation("espoo"); // check access to the Microphone yield return Application.RequestUserAuthorization(UserAuthorization.Microphone); if (!Application.HasUserAuthorization(UserAuthorization.Microphone)) { throw new NotSupportedException("Microphone using not authorized"); } ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => { return true; }; const string SUBSCRIPTION_KEY = "8a414957-b4a9-45e7-8af7-d942f77ff7ff"; const string ACCESS_TOKEN = "7cbe30ec8f6342fbb2c2e8baa80dec3e"; var config = new AIConfiguration(SUBSCRIPTION_KEY, ACCESS_TOKEN, SupportedLanguage.English); apiAiUnity = new ApiAiUnity(); apiAiUnity.Initialize(config); apiAiUnity.OnError += HandleOnError; apiAiUnity.OnResult += HandleOnResult; landmarks = new Dictionary<string, Landmark>(); landmarks.Add( "Helsinki Cathedral", new Landmark("Helsinki Cathedral", "church")); landmarks.Add( "Design Factory", new Landmark("Design Factory", "espoo")); landmarks.Add( "Fortress of Finland", new Landmark("Fortress of Finland", "suomenlinna")); landmarks.Add( "FJORD Helsinki", new Landmark("FJORD Helsinki", "fjord")); //landmarks.Add( "The University of Helsinki", new Landmark("The University of Helsinki", "university")); //landmarks.Add( "The Senate Square", new Landmark("The Senate Square", "square")); }
public ApiAi(AIConfiguration config) { this.config = config; dataService = new AIDataService(this.config); }
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(); } } }
public void SessionTest() { var config = new AIConfiguration(SUBSCRIPTION_KEY, ACCESS_TOKEN, SupportedLanguage.English); var firstService = new AIDataService(config); var secondService = new AIDataService(config); { var weatherRequest = new AIRequest("weather"); var weatherResponse = MakeRequest(firstService, weatherRequest); Assert.IsNotNull(weatherResponse); } { var checkSecondRequest = new AIRequest("check weather"); var checkSecondResponse = MakeRequest(secondService, checkSecondRequest); Assert.IsEmpty(checkSecondResponse.Result.Action); } { var checkFirstRequest = new AIRequest("check weather"); var checkFirstResponse = MakeRequest(firstService, checkFirstRequest); Assert.IsNotNull(checkFirstResponse.Result.Action); Assert.IsTrue(checkFirstResponse.Result.Action.Equals("checked", StringComparison.InvariantCultureIgnoreCase)); } }
public AIWrapper() { //var config = new AIConfiguration("7c0f43c6-03e4-424c-82b5-6c96eefd16c3", "ac7c938ad4b6459191353c8eeae6584c", SupportedLanguage.Spanish); var config = new AIConfiguration("7c0f43c6-03e4-424c-82b5-6c96eefd16c3", "850f2c7c364a441081ff135bddb29c22 ", SupportedLanguage.English); apiAi = new ApiAi(config); }
public SystemRecognitionService(AIConfiguration config) : base(config) { }
public void ComplexParameterTest() { var config = new AIConfiguration(SUBSCRIPTION_KEY, "23e7d37f6dd24e4eb7dbbd7491f832cf", // special agent with domains SupportedLanguage.English); var dataService = new AIDataService(config); var aiRequest = new AIRequest("Turn off TV at 7pm"); var response = MakeRequest(dataService, aiRequest); Assert.AreEqual("domains", response.Result.Source); Assert.AreEqual("smarthome.appliances_off", response.Result.Action); var actionCondition = response.Result.GetJsonParameter("action_condition"); var timeToken = actionCondition.SelectToken("time"); Assert.IsNotNull(timeToken); }
void SelectLanguageSpinner_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e) { var selectedLanguage = languages[e.Position]; var lang = SupportedLanguage.FromLanguageTag(selectedLanguage.LanguageCode); var config = new AIConfiguration("62f2522a-7404-4c28-b9ac-097ca5d8b32d", selectedLanguage.AccessToken, lang); //TODO: Option for verbose logging. Remove this line in production. config.DebugLog = true; if (aiService != null) { aiService.Cancel(); } aiService = AIService.CreateService(this, config); aiService.OnResult += AiService_OnResult; aiService.OnError += AiService_OnError; aiService.ListeningStarted += AiService_ListeningStarted; aiService.ListeningFinished += AiService_ListeningFinished; aiService.AudioLevelChanged += AiService_AudioLevelChanged; }
public void Initialize(AIConfiguration config) { this.config = config; apiAi = new ApiAi(this.config); }