public AnalysisResult Analyze(string imageUrl, string utterance) { var rosetta = new Rosetta(RossyConfig.RosettaConfig); var intent = rosetta.GuessIntent(utterance); var analyzer = GetAnalyzer(intent); List <VisualFeatureTypes> features = analyzer.SetupAnalysisFeatures(); var client = new ComputerVisionClient(new ApiKeyServiceClientCredentials(RossyConfig.GeordiConfig.SubscriptionKey)) { Endpoint = RossyConfig.GeordiConfig.Endpoint }; ImageAnalysis imageAnalysis = client.AnalyzeImageAsync(imageUrl, features).Result; string log = analyzer.ProduceLog(imageAnalysis); var language = rosetta.GuessLanguage(utterance); string speechText; switch (language) { case "it": speechText = analyzer.ProduceSpeechTextItalian(imageAnalysis); break; case "en": default: speechText = analyzer.ProduceSpeechTextEnglish(imageAnalysis); break; } return(new AnalysisResult(speechText, log)); }
public async Task <AnalysisResult> AnalyzeAsync(Stream image, string utterance) { var rosetta = new Rosetta(RossyConfig.RosettaConfig); var intent = rosetta.GuessIntent(utterance); var analyzer = GetAnalyzer(intent); List <VisualFeatureTypes?> features = analyzer.SetupAnalysisFeatures(); var client = new ComputerVisionClient(new ApiKeyServiceClientCredentials(RossyConfig.GeordiConfig.SubscriptionKey)) { Endpoint = RossyConfig.GeordiConfig.Endpoint }; ImageAnalysis imageAnalysis = await client.AnalyzeImageInStreamAsync(image, features); string log = analyzer.ProduceLog(imageAnalysis); var language = rosetta.GuessLanguage(utterance); string speechText = language switch { "it" => analyzer.ProduceSpeechTextItalian(imageAnalysis), "en" => analyzer.ProduceSpeechTextEnglish(imageAnalysis), _ => analyzer.ProduceSpeechTextEnglish(imageAnalysis) }; return(new AnalysisResult(speechText, log)); }