Skip to content

Instantly share code, notes, and snippets.

@Vladislav-Melenchuk
Created February 8, 2026 21:15
Show Gist options
  • Select an option

  • Save Vladislav-Melenchuk/cfa81a8f7a861ce74646ead41c240bb7 to your computer and use it in GitHub Desktop.

Select an option

Save Vladislav-Melenchuk/cfa81a8f7a861ce74646ead41c240bb7 to your computer and use it in GitHub Desktop.
CloudsHW

Завдання

Необходимо разработать приложение с использованием Azure Cognitive Services для обработки изображений, текста и речи.

Анализ изображения (Vision) Приложение должно принимать изображение. С помощью сервиса Azure Vision необходимо: – определить содержимое изображения (описание или теги); – вывести результат анализа пользователю.

Распознавание текста на изображении (OCR) Приложение должно принимать изображение с текстом. С помощью Azure Vision (OCR / Document Intelligence) необходимо: – распознать текст на изображении; – вывести весь найденный текст пользователю.

Работа с речью (Speech) Приложение должно поддерживать голосовой ввод. С помощью Azure Speech-to-Text необходимо: – распознать речь пользователя; – вывести распознанный текст.


Создал Azure Speech и Azure Computer Vision

image image

Меню

image

Анализ изображения

image

Анализ голосового сообщения

image

Коды

using HW10;

class Program
{
    static async Task Main(string[] args)
    {
        Console.WriteLine("Выберите действие:");
        Console.WriteLine("1 - Анализ изображения");
        Console.WriteLine("2 - Распознавание речи (из аудиофайла)");

        var choice = Console.ReadLine();

        switch (choice)
        {
            case "1":
                Console.Write("Введите путь к изображению: ");
                var imagePath = Console.ReadLine();
                VisionAnalysis.AnalyzeImage(imagePath);
                break;

            case "2":
                Console.Write("Введите путь к аудиофайлу: ");
                var audioPath = Console.ReadLine();
                await SpeechRecognition.RecognizeSpeechFromFileAsync(audioPath);
                break;
        }
    }
}

using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;

namespace HW10
{
    public class SpeechRecognition
    {
        public static async Task RecognizeSpeechFromFileAsync(string audioPath)
        {
            string speechKey = "7FOTKwRAubWBeq04wwi91ZGTDc9geLkh1zIn6NYPDX6n3qX0W42XJQQJ99CBACfhMk5XJ3w3AAAYACOG20MY";
            string region = "swedencentral";

            var config = SpeechConfig.FromSubscription(speechKey, region);
            config.SpeechRecognitionLanguage = "ru-RU";

            using var audioInput = AudioConfig.FromWavFileInput(audioPath);
            using var recognizer = new SpeechRecognizer(config, audioInput);

            Console.WriteLine("Распознавание речи...");

            var result = await recognizer.RecognizeOnceAsync();

            if (result.Reason == ResultReason.RecognizedSpeech)
            {
                Console.WriteLine("Распознанный текст:");
                Console.WriteLine(result.Text);
            }
            else
            {
                Console.WriteLine($"Ошибка распознавания: {result.Reason}");
            }
        }
    }
}

using Azure;
using Azure.AI.Vision.ImageAnalysis;

namespace HW10
{
    public class VisionAnalysis
    {
        public static void AnalyzeImage(string imagePath)
        {
            if (!File.Exists(imagePath))
            {
                Console.WriteLine("Файл не найден.");
                return;
            }

            string endpoint = "https://hw10p2.cognitiveservices.azure.com/";
            string key = "36A30ot0NeYd5ya3ppNeqLjzBjpGpFKhiyWZHUkfllaGSrG6usuyJQQJ99CBACfhMk5XJ3w3AAAFACOGMpbN";

            var client = new ImageAnalysisClient(
                new Uri(endpoint),
                new AzureKeyCredential(key));

            using FileStream stream = File.OpenRead(imagePath);

            Response<ImageAnalysisResult> response = client.Analyze(
                BinaryData.FromStream(stream),
                VisualFeatures.Tags | VisualFeatures.Objects
            );

            ImageAnalysisResult result = response.Value;

            Console.WriteLine("=== АНАЛИЗ ИЗОБРАЖЕНИЯ ===\n");

            Console.WriteLine("Теги:");
            foreach (var tag in result.Tags.Values)
            {
                Console.WriteLine($"- {tag.Name} ({tag.Confidence:P})");
            }

            if (result.Objects.Values.Count > 0)
            {
                Console.WriteLine("\nОбнаруженные объекты:");
                foreach (var obj in result.Objects.Values)
                {
                    foreach (var tag in obj.Tags)
                    {
                        Console.WriteLine($"- {tag.Name} ({tag.Confidence:P})");
                    }
                }
            }
            else
            {
                Console.WriteLine("\nОбъекты не обнаружены.");
            }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment