Posted By

warnerBro19 on 03/07/15


Tagged

phone text audio convert csharp Microsoft call voice platform speech sip PBX recognition c# voip text-to-speech ivr autodialer


Versions (?)

How to add text-to-speech and speech-to-text features to your SIP software by using Microsoft Speech Platform in C#?


 / Published in: C#
 

URL: http://www.voip-sip-sdk.com

In my previous snippet I have written about converting text to speech using C#. This code snippet can be used not just for allowing your computer to read txt aloud, but also for speech recognition. To implement this functionality I used Microsoft Speech Platform 11 along with Ozeki VoIP SIP SDK. The first one provides two classes (MSSpeechPlatformSTT, MSSpeechPlatformTTS) for text-to-speech and speech-to-text, and the VoIP SDK ensures the necessary VoIP components. The source code below is ready for use, so you only need to copy&paste it to your Visual Studio, then modify the necessary fields. (Do not forget to add the necessary DLL files to your references: http://www.voip-sip-sdk.com, http://www.microsoft.com/en-us/download/details.aspx?id=27226 )

After creating the necessary using lines and media handler objects, you can implement the text-to-speech and the voice recognition features by using the SetupTextToSpeech() and the SetupSpeechToText() methods.

Have a good time!

  1. using System;
  2. using System.Threading;
  3. using Ozeki.Media.MediaHandlers;
  4. using Ozeki.Media.MediaHandlers.Speech;
  5.  
  6. namespace Microsoft_Speech_Platform
  7. {
  8. class Program
  9. {
  10. static Speaker _speaker;
  11. static Microphone _microphone;
  12. static MediaConnector _connector;
  13. static TextToSpeech _tts;
  14. static SpeechToText _stt;
  15.  
  16. static void Main(string[] args)
  17. {
  18. _microphone = Microphone.GetDefaultDevice();
  19. _speaker = Speaker.GetDefaultDevice();
  20. _connector = new MediaConnector();
  21.  
  22. SetupTextToSpeech();
  23.  
  24. SetupSpeechToText();
  25.  
  26. while (true) Thread.Sleep(10);
  27. }
  28.  
  29. static void SetupTextToSpeech()
  30. {
  31. _tts = new TextToSpeech();
  32. _tts.AddTTSEngine(new MSSpeechPlatformTTS());
  33.  
  34. var voices = _tts.GetAvailableVoices();
  35. foreach (var voice in voices)
  36. {
  37. if (voice.Language.Equals("en-GB"))
  38. _tts.ChangeLanguage(voice.Language, voice.Name);
  39. }
  40.  
  41. _speaker.Start();
  42. _connector.Connect(_tts, _speaker);
  43. _tts.AddAndStartText("Hello World!");
  44. }
  45.  
  46.  
  47. static void SetupSpeechToText()
  48. {
  49. string[] words = {"Hello", "Welcome"};
  50. _stt = SpeechToText.CreateInstance(words);
  51. _stt.WordRecognized += stt_WordRecognized;
  52. _stt.ChangeSTTEngine(new MSSpeechPlatformSTT());
  53.  
  54. var recognizers = _stt.GetRecognizers();
  55. foreach (var recognizer in recognizers)
  56. {
  57. if (recognizer.Culture.Name == "en-GB")
  58. _stt.ChangeRecognizer(recognizer.ID);
  59. }
  60.  
  61. _connector.Connect(_microphone, _stt);
  62. _microphone.Start();
  63. }
  64.  
  65. static void stt_WordRecognized(object sender, SpeechDetectionEventArgs e)
  66. {
  67. Console.WriteLine("Word recognized: {0}", e.Word);
  68. }
  69. }
  70. }

Report this snippet  

You need to login to post a comment.