Ejemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();
            tokenProvider = new AzureAuthToken(TEXT_TRANSLATION_API_SUBSCRIPTION_KEY);
            var languageCodes          = TranslateApi.GetLanguageCodesForTranslate(tokenProvider.GetAccessToken());
            var languageCodesAndTitles = TranslateApi.GetLanguageNamesMethod(tokenProvider.GetAccessToken(), languageCodes);

            //List of languages that have a synthetic voice for text to speech
            speakLanguages = TranslateApi.GetLanguagesForSpeakMethod(tokenProvider.GetAccessToken());
            PopulateLanguagesComboBox(languageCodesAndTitles); //Create the drop down list of langauges
        }
Ejemplo n.º 2
0
        //*****BUTTON TO START TRANSLATION PROCESS
        private void translateButton_Click(object sender, EventArgs e)
        {
            var languageCode = (string)LanguageComboBox.SelectedValue ?? "en";

            //*****BEGIN CODE TO MAKE THE CALL TO THE TRANSLATOR SERVICE TO PERFORM A TRANSLATION FROM THE USER TEXT ENTERED INCLUDES A CALL TO A SPEECH METHOD*****

            string txtToTranslate = textToTranslate.Text;

            string translatedText = TranslateApi.Translate(tokenProvider.GetAccessToken(), txtToTranslate, languageCode);

            translatedTextLabel.Content = "Translation -->   " + translatedText;

            if (speakLanguages.Contains(languageCode) && txtToTranslate != "")
            {
                //call the method to speak the translated text
                SpeakMethod(tokenProvider.GetAccessToken(), translatedText, languageCode);
            }
        }
Ejemplo n.º 3
0
 //*****SPEECH CODE*****
 private void SpeakMethod(string authToken, string textToSpeak, String languageCode)
 {
     TranslateApi.SpeakMethod(authToken, textToSpeak, languageCode, PlayStream);
 }