- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using SpeechLib;
- namespace TTS
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- // speak weather
- try
- {
- SpeechVoiceSpeakFlags spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
- SpVoice voice = new SpVoice();
- if (this.textBox1.Text.Trim() == string.Empty)
- {
- // get weather
- string city = "武汉";
- TTS.cn.com.webxml.www.WeatherWebService wws = new cn.com.webxml.www.WeatherWebService();
- string[] wwsArray = wws.getWeatherbyCityName(city);
- this.textBox1.Text = wwsArray[0] + " " + wwsArray[1] + " " + wwsArray[5] + " " + wwsArray[6] + "。" + Environment.NewLine
- + "\\r\\n" + wwsArray[10] + "。"+ Environment.NewLine + wwsArray[11];
- voice.Speak(this.textBox1.Text, spFlags);
- }
- else
- {
- voice.Speak(this.textBox1.Text, spFlags);
- }
- }
- catch (Exception err)
- {
- MessageBox.Show(err.Message);
- }
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/1010201410594.html
来源: http://www.codesnippet.cn/detail/1010201410594.html