-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpeechTranslation.cshtml.cs
36 lines (28 loc) · 1.09 KB
/
SpeechTranslation.cshtml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using SpeechTranslation;
using System.Collections.Generic;
using System.Linq;
namespace AzureCognitiveServices
{
public class SpeechTranslationModel : PageModel
{
public ICollection<string> Mensagens { get; private set; } = new List<string>(0);
public readonly IEnumerable<Idioma> Idiomas;
[BindProperty]
public IList<string> TraduzirPara { get; set; }
public SpeechTranslationModel() =>
Idiomas = Idioma.IdiomasDisponiveis();
public void OnPost()
{
if (!TraduzirPara.Any())
{
Mensagens.Add("Não foi possível traduzir. Você precisa selecionar pelo menos 1 idioma alvo.");
return;
}
var traduzirDe = Idiomas.FirstOrDefault(n => Request.Form["traduzirDe"].Equals(n.Codigo));
var traduzirPara = Idiomas.Where(i => TraduzirPara.Any(alvo => alvo.Equals(i.Codigo)));
Mensagens = new TraducaoDeFala().Ouvir(traduzirDe, traduzirPara).Result;
}
}
}