主要内容:
 1.使用webClient下载http内容微软技术文档:https://msdn.microsoft.com/library/system.net.webclient.aspx  2.使用Window Media Player播放音频

主要是调用了百度汉字转语音的接口:

http://fanyi.baidu.com/gettts?lan=zh&text=输入的需要转语音的句子&SPD = 5&源=幅

打开链接就会自动下载转好的音频。

下载好的音频为mp3格式,所以使用COM组件中的Window Media Player

在工具箱中右键选择“选择项”然后再选择COM组件中的Window Media Player


软件界面:


程序源码:

使用系统;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;//下载链接音频
using System.IO;//输入输出

namespace 文字转语音
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            textBox1.Text = "请输入需要翻译的内容";
        }
        int n = 0;
        string word = "请输入需要翻译的内容";
        private void button2_Click(object sender, EventArgs e)
        {
            
            if(word!=textBox1.Text)
            {
                n++;
                word = textBox1.Text;
                string remoteUri = "http://fanyi.baidu.com/gettts?lan=zh&text="+word+"&spd=5&source=web"; string fileName = n +“.mp3”; WebClient myWebClient =新的WebClient(); myWebClient.DownloadFile(remoteUri,fileName); } 玩(); } public void play() { string url = System.IO.Directory.GetCurrentDirectory()+“\\”+ n +“。mp3”; //程序当前路径+音乐存放路径 axWindowsMediaPlayer1.URL = url; axWindowsMediaPlayer1.Ctlcontrols.play();
 } private void textBox1_TextChanged(object sender,EventArgs e) {
 }
 私人无效axWindowsMediaPlayer1_Enter(对象发件人,EventArgs e) {
 } } }