1

我试图在C#中构建一个应用程序,该应用程序需要一个音频流(现在来自一个文件,但后来它将成为一个网络流)并从Watson返回转录实时,他们变得可用,类似于演示https://speech-to-text-demo.mybluemix.net/Watson语音文本直播C#代码示例

有谁知道我可以找到一些示例代码,最好在C#中,可以帮助我开始?

我试过这个,基于https://github.com/watson-developer-cloud/dotnet-standard-sdk/tree/development/src/IBM.WatsonDeveloperCloud.SpeechToText.v1的有限文档,但是当我调用RecognizeWithSession时,我得到一个BadRequest错误。我不确定我是否在这条正确的道路上。

static void StreamingRecognize(string filePath) 
    { 
     SpeechToTextService _speechToText = new SpeechToTextService(); 
     _speechToText.SetCredential(<user>, <pw>); 
     var session = _speechToText.CreateSession("en-US_BroadbandModel"); 

     //returns initialized 
     var recognizeStatus = _speechToText.GetSessionStatus(session.SessionId); 

     // set up observe 
     var taskObserveResult = Task.Factory.StartNew(() => 
     { 
      var result = _speechToText.ObserveResult(session.SessionId); 
      return result; 
     }); 

     // get results 
     taskObserveResult.ContinueWith((antecedent) => 
     { 
      var results = antecedent.Result; 
     }); 

     var metadata = new Metadata(); 
     metadata.PartContentType = "audio/wav"; 
     metadata.DataPartsCount = 1; 
     metadata.Continuous = true; 
     metadata.InactivityTimeout = -1; 
     var taskRecognizeWithSession = Task.Factory.StartNew(() => 
     { 
      using (FileStream fs = File.OpenRead(filePath)) 
      { 
       _speechToText.RecognizeWithSession(session.SessionId, "audio/wav", metadata, fs, "chunked"); 
      } 
     }); 
    } 

回答

0

里面的沃森开发云 - SDK的,在你的编程语言,你可以看到一个文件夹,名为例子,你可以访问使用Speech to Text的例子。

SDK支持WebSockets,它可以满足您在转录更多实时音频文件和上传音频文件的需求。

static void Main(string[] args) 
     { 
      Transcribe(); 
      Console.WriteLine("Press any key to exit"); 
      Console.ReadLine(); 
     } 

     // http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/getting_started/gs-credentials.shtml 
     static String username = "<username>"; 
     static String password = "<password>"; 

     static String file = @"c:\audio.wav"; 

     static Uri url = new Uri("wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize"); 

     // these should probably be private classes that use DataContractJsonSerializer 
     // see https://msdn.microsoft.com/en-us/library/bb412179%28v=vs.110%29.aspx 
     // or the ServiceState class at the end 
     static ArraySegment<byte> openingMessage = new ArraySegment<byte>(Encoding.UTF8.GetBytes(
      "{\"action\": \"start\", \"content-type\": \"audio/wav\", \"continuous\" : true, \"interim_results\": true}" 
     )); 
     static ArraySegment<byte> closingMessage = new ArraySegment<byte>(Encoding.UTF8.GetBytes(
      "{\"action\": \"stop\"}" 
     )); 
     // ... more in the link below 
  • 访问SDK C#here
  • 查看API参考资料获取更多信息here
  • IBM Watson Developer here使用Speech to Text的一个完整示例。
相关问题