No tienes acceso a esta clase

¡Continúa aprendiendo! Únete y comienza a potenciar tu carrera

Curso de Azure Cognitive Services

Curso de Azure Cognitive Services

Luis Antonio Ruvalcaba Sanchez

Luis Antonio Ruvalcaba Sanchez

Traducción de voz

13/27
Recursos

Aportes 1

Preguntas 0

Ordenar por:

¿Quieres ver más aportes, preguntas y respuestas de la comunidad?

o inicia sesión.

Código del ejemplo

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;
using Microsoft.CognitiveServices.Speech.Translation;

public class Program
{
    static readonly string SPEECH__SUBSCRIPTION__KEY = "0d0fcb275cf949ce8cdc32c215da56ed";

    static readonly string SPEECH__SERVICE__REGION = "westus";

    static Task Main() {
        Console.WriteLine("Hello World!");
        await TranslateSpeechAsync();
    }

    static async Task TranslateSpeechAsync()
    {
        var translationConfig =
            SpeechTranslationConfig.FromSubscription(SPEECH__SUBSCRIPTION__KEY, SPEECH__SERVICE__REGION);

        var fromLanguage = "es-MX";
        var toLanguages = new List<string> { "en", "fr", "de" };
        translationConfig.SpeechRecognitionLanguage = fromLanguage;
        toLanguages.ForEach(translationConfig.AddTargetLanguage);

        using var recognizer = new TranslationRecognizer(translationConfig);

        Console.Write("Di algo en el idioma : " + fromLanguage);
        Console.WriteLine($"we'll translate into '{string.Join("', '", toLanguages)}'.\n");

        var result = await recognizer.RecognizeOnceAsync();
        if (result.Reason == ResultReason.TranslatedSpeech)
        {
            Console.WriteLine($"Recognized: \"{result.Text}\":");
            foreach (var (language, translation) in result.Translations)
            {
                Console.WriteLine($"Translated into '{language}': {translation}");
            }
        }
    }
}