zoukankan      html  css  js  c++  java
  • Microsoft Speech SDK 开发笔记

      当初做这个,是一时兴起。想做个语音识别,不过。在下不才,没有成功。因为这个SDK的识别率太低太低了。我就好奇为什么手机就可以呢。(如果那个高手知道的话,还请不要吝啬。)

                    好了不废话了,记下笔记。

                    首先是 Microsoft Speech SDK 我用的是5.1,接着是语音包,如果没有好的语音包,做了也没什么用,因为读的不好听。

                    下载这2个东西之后。就可以开发了。

    1 using System;
    2  using System.Collections.Generic;
    3 using System.ComponentModel;
    4 using System.Data;
    5 using System.Drawing;
    6 using System.Text;
    7 using System.Windows.Forms;
    8 using SpeechLib;//SDK包含的DLL
    9
    10 namespace WindowsApplicationSpeech
    11 {
    12 public partial class Form1 : Form
    13 {
    14 public Form1()
    15 {
    16 InitializeComponent();
    17
    18 }
    19 SpVoice voice = new SpVoice();
    20
    21 private void btnSpeek_Click(object sender, EventArgs e)
    22 {
    23 if ((richTextBox1.Text == "") || (richTextBox1.Text == string.Empty))
    24 {
    25 return;
    26 } //异步读
    27 voice.Speak(richTextBox1.Text, SpeechVoiceSpeakFlags.SVSFlagsAsync);//使用异步的方式去读RichTextBox里面的文本。
    28 }
    29
    30 private void btnExit_Click(object sender, EventArgs e)
    31 {
    32 this.Dispose();
    33 }
    34
    35 private void btnPause_Click(object sender, EventArgs e)
    36 {
    37 voice.Pause();//暂停
    38 }
    39
    40 private void btnResume_Click(object sender, EventArgs e)
    41 {
    42 voice.Resume();//继续
    43 }
    44 }
    45 }
    46
    47

    主要方法介绍:

    Object: SpVoice  (这是一个接口

    Speak Method

    The Speak method initiates the speaking of a text string, a text file, an XML file, or a wave file by the voice.

    The Speak method can be called synchronously or asynchronously. When called synchronously, the method does not return until the text has been spoken; when called asynchronously, it returns immediately, and the voice speaks as a background process.

    When synchronous speech is used in an application, the application's execution is blocked while the voice speaks, and the user is effectively locked out. This may be acceptable for simple applications, or those with no graphical user interface (GUI), but when sophisticated user interaction is intended, asynchronous speaking will generally be more appropriate.

    上面是 SDK里面的原文,我之所以写这个例子是没有办法的事,写不了语音识别,就写阅读器。因为喜欢看小说,看时间长了就眼疼,所以,下一个语音包之后,听小说也是不错的选择,如果那位大大能把语音识别做好,也希望能拿出来!

    一下是函数原型 SDK的例子多半是 VB 和 C++ 所以我直接用C#,方便学C#的朋友。

    SpVoice.Speak(
         Text As String,
         [Flags As SpeechVoiceSpeakFlags = SVSFDefault]
    ) As Long

    Parameters

    Text
    The text to be spoken, or if the SVSFIsFilename flag is included in the Flags parameter, the path of the file to be spoken.
    Flags
    [Optional] Flags. Default value is SVSFDefault.

    Return Value

    A Long variable containing the stream number. When a voice enqueues more than one stream by speaking asynchronously, the stream number is necessary to associate events with the appropriate stream.

  • 相关阅读:
    JS 关于 URL 的编码或解码方法
    PHP 获取上一个页面的url
    踩坑 Uncaught RangeError: Maximum call stack size exceeded
    Wordpress 数据库查询错误 Call to a member function get_results() on null
    Chrome autocomplete="off"无效
    js 遍历对象属性(for in、Object.keys、Object.getOwnProperty) 以及高效地输出 js 数组
    PHP PDO fetch() 详解
    Wordpress 自定义文章类型添加 Categoried、Tags
    Mac: mac git 的安装 及实现自动补全
    Uncaught TypeError: Cannot read property of undefined In JavaScript
  • 原文地址:https://www.cnblogs.com/LearningC/p/1945204.html
Copyright © 2011-2022 走看看