Esempio n. 1
0
        private void listen_Click(object sender, EventArgs e)
        {
            /* Plays the text that is put in the textToSpeech box of the program
             * The box can be modified and it will speak the modified text.
             */

            SoundPlayer player = new SoundPlayer();

            try
            {
                if (ICAO_Textbox.Text.Count() == 0)
                {
                    MessageBox.Show("No ICAO code provided. If the ICAO code is provided, it is invalid or you have not clicked the Search button. ERROR 4", "ERROR 4");
                }
                else if (dep_runways.Text == "" || arr_runways.Text == "")
                {
                    MessageBox.Show("Enter the arrival AND departure runways. ERROR 1", "ERROR 1");
                }
                else if (textToSpeech.Text == "")
                {
                    MessageBox.Show("I have nothing to say! ERROR 5", "ERROR 5");
                }
                else if (listen.Text == "Stop")
                {
                    player.Stop();
                    listen.Text = "Listen";
                }
                else
                {
                    listen.Text = "Stop";
                    VoiceService.LanguageServiceClient client = new VoiceService.LanguageServiceClient();
                    //SoundPlayer player = new SoundPlayer(client.Speak("8F80F32F200F7A556D3DD92CE6DAFC6DCA3B9BC8", textToSpeech.Text, "en", "audio/wav"));
                    player.SoundLocation = client.Speak("8F80F32F200F7A556D3DD92CE6DAFC6DCA3B9BC8", textToSpeech.Text, "en", "audio/wav");
                    player.Play();
                }
            }
            catch (Exception ex)
            {
                string exception = ex.ToString();
                if (exception.Contains("ArgumentOutOfRangeException"))
                {
                    MessageBox.Show("Invalid Entry. Please try again. ERROR 6", "ERROR 6");
                    listen.Text = "Listen";
                }
                else
                {
                    MessageBox.Show(ex.Message, "ERROR 100");
                    listen.Text = "Listen";
                }
            }
            //player.Dispose();
        }
Esempio n. 2
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            //Saves the spoken text to the directory of the program in a wav file.
            WebClient wc = new WebClient();

            try
            {
                if (textToSpeech.Text == "" || dep_runways.Text == "" || arr_runways.Text == "" || ICAO_Search.Text == "")
                {
                    MessageBox.Show("Could not save ATIS! A required field is missing. Please check all fields are filled in.");
                }
                else
                {
                    VoiceService.LanguageServiceClient client = new VoiceService.LanguageServiceClient();
                    wc.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)");
                    byte[]     mp3Bytes = wc.DownloadData(client.Speak("8F80F32F200F7A556D3DD92CE6DAFC6DCA3B9BC8", textToSpeech.Text, "en", "audio/wav"));//API, TEXT, LANGUAGE, TYPE
                    string     fileOut  = "atis.mp3";
                    FileStream fs       = new FileStream(fileOut, FileMode.Create);
                    fs.Write(mp3Bytes, 0, mp3Bytes.Length);
                    fs.Close();
                    MessageBox.Show("ATIS file saved.", "ATIS Saved");
                }
            }
            catch (Exception ex)
            {
                string error = ex.ToString();
                if (error.Contains("ArgumentOutOfRangeException"))
                {
                    MessageBox.Show("Something is not right.\n1) Check the ICAO code.\n2) Check runway entries.\n3) Is there anything written on the textbox above? ERROR 1", "ERROR 1");
                }
                else
                {
                    MessageBox.Show(ex.ToString(), "ERROR 100");
                }
            }
        }