2012-08-13 53 views
1

我已經做了一個簡單的程序來識別語音使用SAPI 5.4,我想問我是否可以添加更多的語言到TTS和ASR,謝謝 這是我讓你有人需要看看的代碼它C#SAPI 5.4語言?

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using SpeechLib; 
using System.Globalization; 
using System.Speech.Recognition; 

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 

     // Speech Recognition Object 
     SpSharedRecoContext listener; 

     // Grammar object 
     ISpeechRecoGrammar grammar; 

     public Form1() 
     { 
      InitializeComponent(); 
     } 
     public string ps; 
     private void button1_Click(object sender, EventArgs e) 
     { 

     if (btnListen.Text == "Start Listening") 
     { 
       try 
       { 

        listener = new SpeechLib.SpSharedRecoContext(); 
        listener.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(listener_Reco); 
        grammar = listener.CreateGrammar(0); 
        grammar.DictationLoad("", SpeechLoadOption.SLOStatic); 
        grammar.DictationSetState(SpeechRuleState.SGDSActive); 
        btnListen.Text = "Stop Listening"; 
        if (ps == "1") 
        { 
        listener.Resume(); 
        ps = "0"; 
        } 
       } 
       catch (Exception ex) 
       { 
        MessageBox.Show(ex.Message); 
       } 
     } 
     else if (btnListen.Text == "Stop Listening") 
     { 
      listener.Pause(); 
      btnListen.Text = "Start Listening"; 
      if (ps == "0") 
      { 
      ps = "1"; 
      } 
      } 

      } 
     public void listener_Reco(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult Result) 
     { 
      string heard = Result.PhraseInfo.GetText(0, -1, true); 
      textBox1.Text += " " + heard; 

     } 

     private void button1_Click_1(object sender, EventArgs e) 
     { 
      WinXP winxp = new WinXP(); 
      winxp.Show(); 
      this.Hide(); 
     } 


     string getOSInfo() 
     { 
      //Get Operating system information. 
      OperatingSystem os = Environment.OSVersion; 
      //Get version information about the os. 
      Version vs = os.Version; 

      //Variable to hold our return value 
      string operatingSystem = ""; 

      if (os.Platform == PlatformID.Win32Windows) 
      { 
       //This is a pre-NT version of Windows 
       switch (vs.Minor) 
       { 
        case 0: 
         operatingSystem = "95"; 
         break; 
        case 10: 
         if (vs.Revision.ToString() == "2222A") 
          operatingSystem = "98SE"; 
         else 
          operatingSystem = "98"; 
         break; 
        case 90: 
         operatingSystem = "Me"; 
         break; 
        default: 
         break; 
       } 
      } 
      else if (os.Platform == PlatformID.Win32NT) 
      { 
       switch (vs.Major) 
       { 
        case 3: 
         operatingSystem = "NT 3.51"; 
         break; 
        case 4: 
         operatingSystem = "NT 4.0"; 
         break; 
        case 5: 
         if (vs.Minor == 0) 
          operatingSystem = "2000"; 
         else 
          operatingSystem = "XP"; 
         break; 
        case 6: 
         if (vs.Minor == 0) 
          operatingSystem = "Vista"; 
         else 
          operatingSystem = "7"; 
         break; 
        default: 
         break; 
       } 
      } 
      //Make sure we actually got something in our OS check 
      //We don't want to just return " Service Pack 2" or " 32-bit" 
      //That information is useless without the OS version. 
      if (operatingSystem != "") 
      { 
       //Got something. Let's prepend "Windows" and get more info. 
       operatingSystem = "Windows " + operatingSystem; 
       //See if there's a service pack installed. 
       if (os.ServicePack != "") 
       { 
        //Append it to the OS name. i.e. "Windows XP Service Pack 3" 
        operatingSystem += " " + os.ServicePack; 
       } 
       //Append the OS architecture. i.e. "Windows XP Service Pack 3 32-bit" 
       operatingSystem += " " + getOSArchitecture().ToString() + "-bit"; 
      } 
      //Return the information we've gathered. 
      return operatingSystem; 
     } 

     int getOSArchitecture() 
     { 
      string pa = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE"); 
      return ((String.IsNullOrEmpty(pa) || String.Compare(pa, 0, "x86", 0, 3, true) == 0) ? 32 : 64); 
     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 
      string OS = getOSInfo(); 
      if (OS.Contains("XP")) 
      { 
       btnXP.Visible = true; 
      } 
      else 
      { 
       btnXP.Visible = false; 
       btnYes2.Visible = true; 
       btnNo2.Visible = true; 
       btnNo.Visible = false; 
       btnYes.Visible = false; 
      } 
     } 




    } 
} 

PS我有一個問題,當恢復識別器

+0

不是一個選項,識別器隨Windows一起預裝。當一個德國用戶購買德語版本​​的Windows時,他會理解他用德語聊天,並與德語交談。支持可安裝的語言包需要花錢,如http://msdn.microsoft.com/en-us/library/ms986793.aspx – 2012-08-13 15:13:13

+0

有沒有辦法讓這個Microsoft Speech Server語言包文件免費? – 2012-08-13 19:35:58

+0

任何東西都可以免費獲得。然而,關於槍的合適大小的問題不過是這裏的主題。 – 2012-08-13 19:43:41

回答

2

這取決於你用識別器做一點點。是的,桌面操作系統(Windows Vista,7)帶有與操作系統語言版本綁定的識別器。但是,微軟也免費贈送(無需武器)在服務器上使用的識別引擎(但也可用於桌面操作系統)。有許多不同的免費語言。

桌面和服務器識別器庫之間存在一些差異。我的理解是,桌面識別器可以訓練特定的揚聲器,支持更高質量的音頻輸入,幷包括聽寫語法。這些設計用於一次只能有一個揚聲器的桌面應用。服務器識別器設計用於電話質量的音頻,不可訓練,並且需要有限的語法(無聽寫)。服務器引擎設計用於更高規模和多個同步揚聲器(如IVR或SpeechServer應用程序中)。

參見:

對於某些背景,請參閱What is the difference between System.Speech.Recognition and Microsoft.Speech.Recognition?