日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C#WPF 语音开发教程 TTS中英文语音(男女声音)朗读 源代码下载 csdn tts(text to sound) 一步一步 教你制作语音软件 附图和源代码

發布時間:2023/12/20 C# 33 豆豆

C#WPF? 語音開發教程? TTS中文語音朗讀 一步一步 教你制作語音軟件??

?附圖和源代碼

使用時,請確認電腦喇叭打開,并且不是靜音額。

效果展示

?

一 項目準備

1.vs2012開發平臺

2.微軟的語音軟件庫

下載:http://download.csdn.net/detail/wyx100/8431269?(含實例項目源代碼)

二.開發目標

制作一個語音軟件,可以朗讀文字;

多個語音庫:男音和女音、支持英文和中文朗讀;

支持選擇播放設備

支持朗讀語速選擇

支持音量選擇

三 開發過程

1.新建WpfSpeechDemo工程

文件(vs開發平臺左上角)----新建(快捷方式 Ctrl+Shift+New)

2.導入微軟語音庫

?

3.建立軟件界面

見開始? 效果展示

4.軟件功能開發

支持語音庫選擇

支持選擇播放設備

支持朗讀語速選擇

支持音量選擇

?

四 軟件代碼

1.界面代碼

<Window x:Class="WpfSpeechDemo.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Title="WpfSpeechDemo" Height="350" Width="525"><Grid><ComboBox x:Name="cmbVoices" HorizontalAlignment="Left" Margin="86,23,0,0" VerticalAlignment="Top" Width="222" SelectionChanged="cmbVoices_SelectionChanged"/><ComboBox x:Name="cmbAudioOut" HorizontalAlignment="Left" Margin="86,69,0,0" VerticalAlignment="Top" Width="222" SelectionChanged="cmbAudioOut_SelectionChanged"/><Label Content="語音庫(引擎): " HorizontalAlignment="Left" Margin="0,23,0,0" VerticalAlignment="Top" Width="81"/><Label Content="語音輸出方式: " HorizontalAlignment="Left" Margin="0,65,0,0" VerticalAlignment="Top" Width="81"/><Button Content="朗讀|Speek" HorizontalAlignment="Left" Margin="33,119,0,0" VerticalAlignment="Top" Width="104" Click="bt_speek_Click"/><Button Content="停止|Stop" HorizontalAlignment="Left" Margin="170,119,0,0" VerticalAlignment="Top" Width="93" RenderTransformOrigin="2.042,0.064" Click="bt_stop_Click"/><TextBox Name="tbspeech" HorizontalAlignment="Left" Height="125" Margin="20,172,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="484" BorderThickness="3" Text="Wpf語音,hello world!"><TextBox.BorderBrush><LinearGradientBrush EndPoint="0,20" MappingMode="Absolute" StartPoint="0,0"><GradientStop Color="#FFABADB3" Offset="0.05"/><GradientStop Color="#FFE2E3EA" Offset="0.07"/><GradientStop Color="#FF1A72C9" Offset="1"/></LinearGradientBrush></TextBox.BorderBrush></TextBox><Slider x:Name="tbarRate" Orientation="Vertical" Minimum="0" Maximum="10"IsMoveToPointEnabled="True"AutoToolTipPrecision="2" AutoToolTipPlacement="BottomRight"TickPlacement="BottomRight"Ticks="1, 2, 3, 4, 5, 6, 7, 8, 9,10" IsSelectionRangeEnabled="true"SelectionStart="1" SelectionEnd="9" HorizontalAlignment="Left" Margin="357,51,0,0" VerticalAlignment="Top" Height="103" ValueChanged="tbarRate_ValueChanged" Background="#FFEFEBF0"/><Slider x:Name="trbVolume" Orientation="Vertical" Minimum="0" Maximum="10"IsMoveToPointEnabled="True"AutoToolTipPrecision="2" AutoToolTipPlacement="BottomRight"TickPlacement="BottomRight"Ticks="1, 2, 3, 4, 5, 6, 7, 8, 9,10" IsSelectionRangeEnabled="true"SelectionStart="1" SelectionEnd="9" HorizontalAlignment="Left" Margin="426,51,0,0" VerticalAlignment="Top" Height="103" ValueChanged="trbVolume_ValueChanged" Background="#FFF2EFF3"/><Label Content="語速" HorizontalAlignment="Left" Margin="350,19,0,0" VerticalAlignment="Top" Width="35" /><Label Content="音量" HorizontalAlignment="Left" Margin="418,19,0,0" VerticalAlignment="Top" Width="35"/></Grid> </Window>

2.功能代碼

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes;using DotNetSpeech;//cs文件中引入庫namespace WpfSpeechDemo {/// <summary>/// MainWindow.xaml 的交互邏輯/// </summary>public partial class MainWindow : Window{SpVoice speech = new SpVoice();int speechRate = 0;int volume = 70;public MainWindow(){InitializeComponent();init();}private void init(){//初始化語音引擎列表foreach (ISpeechObjectToken Token in speech.GetVoices(string.Empty, string.Empty)){cmbVoices.Items.Add(Token.GetDescription(49));}//取得音頻輸出列表foreach (ISpeechObjectToken AudioOut in speech.GetAudioOutputs(string.Empty, string.Empty)){cmbAudioOut.Items.Add(AudioOut.GetDescription(49));}cmbVoices.SelectedIndex = 0;cmbAudioOut.SelectedIndex = 0;tbarRate.Value = speechRate;trbVolume.Value = volume;}private void tbarRate_Scroll(object sender, EventArgs e){speech.Rate = (int)tbarRate.Value;}private void trbVolume_Scroll(object sender, EventArgs e){speech.Volume = (int)trbVolume.Value;}private void cmbVoices_SelectionChanged(object sender, SelectionChangedEventArgs e){speech.Voice = speech.GetVoices(string.Empty, string.Empty).Item(cmbVoices.SelectedIndex);}private void cmbAudioOut_SelectionChanged(object sender, SelectionChangedEventArgs e){speech.AudioOutput = speech.GetAudioOutputs(string.Empty, string.Empty).Item(cmbAudioOut.SelectedIndex);}private void bt_speek_Click(object sender, EventArgs e){//終止先前朗讀,如果有speech.Speak(" ", SpeechVoiceSpeakFlags.SVSFlagsAsync);speech.Speak(tbspeech.Text, SpeechVoiceSpeakFlags.SVSFlagsAsync);}private void bt_stop_Click(object sender, EventArgs e){speech.Speak("", SpeechVoiceSpeakFlags.SVSFlagsAsync);}private void tbarRate_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e){speech.Rate = (int)e.NewValue;}private void trbVolume_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e){speech.Volume = (int)e.NewValue;}} }

五 編譯和運行

總結

以上是生活随笔為你收集整理的C#WPF 语音开发教程 TTS中英文语音(男女声音)朗读 源代码下载 csdn tts(text to sound) 一步一步 教你制作语音软件 附图和源代码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。