vs C# wpf 如何引入(导入)库、dll

vs  C# wpf  如何引入(导入)库、dll

说明:一般需要在两个地方引入,

1.程序集火项目中引入;

2.在cs或xaml文件中引入

1.程序集或项目中引入

例如:引入DotNetSpeech.dll库

vs  C# wpf  如何引入(导入)库、dll

 vs  C# wpf  如何引入(导入)库、dll

vs  C# wpf  如何引入(导入)库、dll

vs  C# wpf  如何引入(导入)库、dll

2.在cs或xaml文件中引入

添加:

using DotNetSpeech;//cs文件中引入库

 

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;
        }

    }
}

 

vs C# wpf 如何引入(导入)库、dll

上一篇:C# DES加密解密


下一篇:C# 1 – 委托的基本概念