2013-02-14 1 views
10

マイクと話す代わりに.wavsを与える認識プログラムをプログラム的にトレーニングすることは可能ですか?SpeechRecognitionEngineをプログラム的にトレーニングし、オーディオファイルをc#またはvb.netのテキストに変換する方法

これはどうすればいいですか?現在、私は0wavファイルの音声認識を実行するコードを持っており、認識されたテキストをコンソールに書き込みます。

Imports System.IO 
Imports System.Speech.Recognition 
Imports System.Speech.AudioFormat 

Namespace SampleRecognition 
    Class Program 
     Shared completed As Boolean 

     Public Shared Sub Main(ByVal args As String()) 
      Using recognizer As New SpeechRecognitionEngine() 
       Dim dictation As Grammar = New DictationGrammar() 
       dictation.Name = "Dictation Grammar" 
       recognizer.LoadGrammar(dictation) 
       ' Configure the input to the recognizer. 
       recognizer.SetInputToWaveFile("C:\Users\ME\v02\0.wav") 

       ' Attach event handlers for the results of recognition. 
       AddHandler recognizer.SpeechRecognized, AddressOf recognizer_SpeechRecognized 
       AddHandler recognizer.RecognizeCompleted, AddressOf recognizer_RecognizeCompleted 

       ' Perform recognition on the entire file. 
       Console.WriteLine("Starting asynchronous recognition...") 
       completed = False 
       recognizer.RecognizeAsync() 
       ' Keep the console window open. 
       While Not completed 
        Console.ReadLine() 
       End While 
       Console.WriteLine("Done.") 
      End Using 

      Console.WriteLine() 
      Console.WriteLine("Press any key to exit...") 
      Console.ReadKey() 
     End Sub 

     ' Handle the SpeechRecognized event. 
     Private Shared Sub recognizer_SpeechRecognized(ByVal sender As Object, ByVal e As SpeechRecognizedEventArgs) 
      If e.Result IsNot Nothing AndAlso e.Result.Text IsNot Nothing Then 
       Console.WriteLine(" Recognized text = {0}", e.Result.Text) 
      Else 
       Console.WriteLine(" Recognized text not available.") 
      End If 
     End Sub 

     ' Handle the RecognizeCompleted event. 
     Private Shared Sub recognizer_RecognizeCompleted(ByVal sender As Object, ByVal e As RecognizeCompletedEventArgs) 
      If e.[Error] IsNot Nothing Then 
       Console.WriteLine(" Error encountered, {0}: {1}", e.[Error].[GetType]().Name, e.[Error].Message) 
      End If 
      If e.Cancelled Then 
       Console.WriteLine(" Operation cancelled.") 
      End If 
      If e.InputStreamEnded Then 
       Console.WriteLine(" End of stream encountered.") 
      End If 
      completed = True 
     End Sub 
    End Class 
End Namespace 

EDIT私はトレーニング・ウィザードを使用して理解

スタート をクリックして開く音声認識によって達成この

を行うことが有益であるボタン - >コントロールパネル - > Access-のしやすさ>音声認識

カスタムwavまたはmp3ファイルで音声認識をトレーニングする方法はありますか?

トレーニングウィザード(コントロールパネルのトレーニングUI)を使用する場合、トレーニングファイルは {AppData}¥Local¥Microsoft¥Speech¥Files¥TrainingAudioに格納されます。

トレーニングウィザードを使用する代わりに、カスタムトレーニングを使用する方法やカスタムトレーニングを行う方法はありますか?

スピーチコントロールパネルのキーます。HKCU \ Software \ Microsoft \スピーチ\ RecoProfiles \ {トークンProfileGUID}で{00000000-0000-0000-0000-0000000000000000を}トレーニングオーディオファイルのレジストリエントリを作成します\ファイル

コードで作成したレジストリエントリをそこに配置する必要がありますか?

これは、私自身のwavファイルと単語とフレーズのリストを使用してカスタムトレインしたいのです。それから、すべてを他のシステムに転送します。

答えて

2

あなたはSAPIエンジン(ないマネージAPI)

はここで行う方法についてlinkだを使用してカスタムトレーニングを生成することができ、それ(ただし曖昧ビット)

4

それは、C#を使用してSAPIを訓練することは確かに可能です。適切なオーディオ入力をバインド&あなたはインプロセス認識を作成@Eric Brown answered the procedure

  • を.hereのC#からトレーニングモードAPIにアクセスするためにSAPI周りspeechlibラッパーを使用することができます。
  • 認識のためのオーディオを保持していることを確認してください。後でそれが必要になります。
  • トレーニングするテキストを含む文法を作成します。
  • 認識が行われたときに認識プログラムを一時停止するように文法の状態を設定します。 (これは、同様に、オーディオファイルからのトレーニングに役立ちます。)

    認識が発生した場合:

  • が認識されたテキストおよび保持オーディオを取得します。

  • CoCreateInstance(CLSID_SpStream)を使用してストリームオブジェクトを作成します。
  • ISpRecognizer :: GetObjectTokenとISpObjectToken :: GetStorageFileNameを使用してトレーニングオーディオファイルを作成し、それをストリームにバインドします(ISpStream :: BindToFileを使用)。
  • 保持されているオーディオをストリームオブジェクトにコピーします。
  • QI ISpTranscriptインターフェイスのストリームオブジェクト。ISpTranscript :: AppendTranscriptを使用して、認識されたテキストをストリームに追加します。
  • 次の発話の文法を更新し、認識プログラムを再開し、トレーニングテキストがなくなるまで繰り返します。

その他のオプションは、所望の出力で一度SAPIを訓練することができ、その後、コードでプロファイルを取得し、他のシステムにそれを運ぶ、次のコードは、ISpeechObjectTokensがGetProfilesメソッドが返す:

オブジェクトを返します。利用可能なユーザ スピーチプロファイルの選択。プロファイルは、音声構成 データベースに一連のトークンとして格納され、各トークンは というプロファイルを表します。 GetProfilesは利用可能なすべてのプロファイルトークンを取得します。返したリスト は、ISpeechObjectTokensオブジェクトです。追加または追加 トークンに関する詳細情報は、ISpeechObjectTokensに関連付けられた メソッドで参照できます。トークン検索は、 の属性を使用してさらに精製されてもよい。指定されたRequiredAttributes 検索属性に一致するトークンのみが返されます。 RequiredAttributesキーに一致するトークンのうち、OptionalAttributesは、OptionalAttributesに一致する順序で の順番にデバイスをリストします。検索属性が指定されていない場合は、すべて のトークンが返されます。オーディオデバイスが条件に一致しない場合、 GetAudioInputsは空の選択、つまり、0のISpeechObjectTokens :: Count プロパティを持つ ISpeechObjectTokensコレクションを返します。 See Object Tokens and Registry Settings White Paper for a list of SAPI 5-defined attributes

Public SharedRecognizer As SpSharedRecognizer 
Public theRecognizers As ISpeechObjectTokens 

Private Sub Command1_Click() 
    On Error GoTo EH 

    Dim currentProfile As SpObjectToken 
    Dim i As Integer 
    Dim T As String 
    Dim TokenObject As ISpeechObjectToken 
    Set currentProfile = SharedRecognizer.Profile 

    For i = 0 To theRecognizers.Count - 1 
     Set TokenObject = theRecognizers.Item(i) 

     If tokenObject.Id <> currentProfile.Id Then 
      Set SharedRecognizer.Profile = TokenObject 
      T = "New Profile installed: " 
      T = T & SharedRecognizer.Profile.GetDescription 
      Exit For 
     Else 
      T = "No new profile has been installed." 
     End If 
    Next i 

    MsgBox T, vbInformation 

EH: 
    If Err.Number Then ShowErrMsg 
End Sub 

Private Sub Form_Load() 
    On Error GoTo EH 

    Const NL = vbNewLine 
    Dim i, idPosition As Long 
    Dim T As String 
    Dim TokenObject As SpObjectToken 

    Set SharedRecognizer = CreateObject("SAPI.SpSharedRecognizer") 
    Set theRecognizers = SharedRecognizer.GetProfiles 

    For i = 0 To theRecognizers.Count - 1 
     Set TokenObject = theRecognizers.Item(i) 
     T = T & TokenObject.GetDescription & "--" & NL & NL 
     idPosition = InStrRev(TokenObject.Id, "\") 
     T = T & Mid(TokenObject.Id, idPosition + 1) & NL 
    Next i 

    MsgBox T, vbInformation 

EH: 
    If Err.Number Then ShowErrMsg 
End Sub 

Private Sub ShowErrMsg() 

    ' Declare identifiers: 
    Dim T As String 

    T = "Desc: " & Err.Description & vbNewLine 
    T = T & "Err #: " & Err.Number 
    MsgBox T, vbExclamation, "Run-Time Error" 
    End 

End Sub 
関連する問題