.Net里面自带了一个语音类库:System.Speech,调用系统的语音功能,就能实现string到语音的转换。
首先呢,我们要下载System.Speech的dll
然后新建项目SpeechDome,这里我用的是WinForm,当然你也可以用其他的。
调用程序集下面的Synthesis.SpeechSynthesizer();
using System;
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.Speech;
using System.Speech.Synthesis;
namespace SpeechDome
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//实例化SpeechSynthesizer类
var reader = new System.Speech.Synthesis.SpeechSynthesizer();
//要播放的语音
var yuying = "我,是一个,菜鸟……程序员!";
//异步使用字符串内容的语言,播放
reader.SpeakAsync(yuying);
}
}
}
打完收工。
我是云中小生,代码之外,诗和远方