public UdiskMonitor(string info) : base() { InitializeComponent(); SpVoice spv = new SpVoice(); if (spv == null) { return; } ISpeechObjectTokens arrVoices = spv.GetVoices(string.Empty, string.Empty); List <string> arrlist = new List <string>(); for (int i = 0; i < arrVoices.Count; i++) { arrlist.Add(arrVoices.Item(i).GetDescription(0)); } cmbVoices.DataSource = arrlist; Point p = new Point(500, 1024); this.Location = p; t = new byte[4]; t[0] = 5; label1.Text = info; speak_Thread = new Thread(new ThreadStart(start_Speak)); speak_Thread.Start(); linkLabel1.Visible = true; linkLabel1.Text = "马上开始扫描"; linkLabel1.LinkColor = Color.Red; }
private void initialize() { language = "DE"; tokenCat = new SpObjectTokenCategory(); tokenCat.SetId(SpeechLib.SpeechStringConstants.SpeechCategoryVoices, false); tokens = tokenCat.EnumerateTokens(null, null); int n = 0; int languageIndex = 0; foreach (SpObjectToken item in tokens) { if (language == "DE") { if (item.GetDescription(0).Contains("Hedda")) { languageIndex = n; GermanLanguageIndex = n; } } if (language == "ENG") { if (item.GetDescription(0).Contains("Zira")) { languageIndex = n; EnglishLanguageIndex = n; } } n++; } voice = new SpVoice(); voice.Voice = tokens.Item(languageIndex); speechFileMode = SpeechStreamFileMode.SSFMCreateForWrite; }
void OnGUI() { SpObjectTokenCategory tokenCat = new SpObjectTokenCategory(); tokenCat.SetId(SpeechLib.SpeechStringConstants.SpeechCategoryVoices, false); ISpeechObjectTokens tokens = tokenCat.EnumerateTokens(null, null); }
private void Initialize() { try { voice = new SpVoiceClass(); voice.EndStream += Voice_EndStream; ISpeechObjectTokens objTokens = voice.GetVoices("", ""); const string useVoice = "ScanSoft Mei-Ling_Full_22kHz"; int useIndex = -1; for (int i = 0; i < objTokens.Count; i++) { SpObjectToken sot = objTokens.Item(i); if (sot.GetDescription(0) == useVoice) { useIndex = i; break; } } if (useIndex == -1) { useIndex = 0; } voice.Voice = objTokens.Item(useIndex); } catch (Exception e) { MessageBox.Show("Error:" + e.Message); } }
// Selects the voice corresponding to the language setting void Awake() { language = WestdriveSettings.language; #if TTS SpObjectTokenCategory tokenCat = new SpObjectTokenCategory(); tokenCat.SetId(SpeechLib.SpeechStringConstants.SpeechCategoryVoices, false); ISpeechObjectTokens tokens = tokenCat.EnumerateTokens(null, null); int n = 0; int languageIndex = 0; foreach (SpObjectToken item in tokens) { if (language == "DE") { if (item.GetDescription(0).Contains("Hedda")) { languageIndex = n; } } if (language == "ENG") { if (item.GetDescription(0).Contains("Zira")) { languageIndex = n; } } n++; } voice = new SpVoice(); voice.Voice = tokens.Item(languageIndex); #endif }
private void voices() { SpVoice speechSynthesizer = new SpVoice(); availableVoices = speechSynthesizer.GetVoices(); string name; string desc; string gender; string age; string lang; string vendor; System.Collections.Generic.List <Model.Voice> voices = new System.Collections.Generic.List <Model.Voice>(); foreach (SpObjectToken voice in availableVoices) { if (voice.Id.StartsWith(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\eSpeakNG_")) { if (Util.Config.DEBUG) { Debug.LogWarning("eSpeak-NG voices are ignored!"); } } else { name = voice.GetAttribute("name"); desc = voice.GetDescription(); gender = voice.GetAttribute("gender"); age = voice.GetAttribute("age"); lang = voice.GetAttribute("language"); vendor = voice.GetAttribute("vendor"); if (string.IsNullOrEmpty(lang)) { lang = "409"; //en-US } int langCode = int.Parse(lang, System.Globalization.NumberStyles.HexNumber); string culture; if (!Util.Helper.LocaleCodes.TryGetValue(langCode, out culture)) { Debug.LogWarning("Voice with name '" + name + "' has an unknown language code: " + langCode + "(" + lang + ")!"); culture = "en-us"; } voices.Add(new Model.Voice(name, desc, Util.Helper.StringToGender(gender), age, culture, voice.Id, vendor)); } } cachedVoices = voices.OrderBy(s => s.Name).ToList(); if (Util.Constants.DEV_DEBUG) { Debug.Log("Voices read: " + cachedVoices.CTDump()); } }
private void Face_Detect_and_Greet_Load(object sender, EventArgs e) { tokens = spVoice.GetVoices("", ""); for (int i = 0; i < tokens.Count; i++) comboBoxVoice.Items.Add(tokens.Item(i).GetAttribute("Name")); if (tokens.Count > 0) comboBoxVoice.SelectedIndex = 0; }
private void Form1_Load(object sender, EventArgs e) { trRate.Minimum = -10; trRate.Maximum = 10; trRate.Value = 0; SpVoice spVoice = new SpVoice(); ISpeechObjectTokens arrVoice = spVoice.GetVoices(); string s; for (int i = 0; i < 5; i++) { cboVoice.Items.Add(arrVoice.Item(i).GetDescription()); } }
private void InsertTextToSpeech_Load(object sender, EventArgs e) { tokens = spVoice.GetVoices("", ""); for (int i = 0; i < tokens.Count; i++) { comboBoxVoice.Items.Add(tokens.Item(i).GetAttribute("Name")); } if (tokens.Count > 0) { comboBoxVoice.SelectedIndex = 0; } }
public Speak(Conductor c, String text, int voiceIndex) { conductor = c; tokens = spVoice.GetVoices("", ""); //currentVoiceIndex = comboBoxVoice.SelectedIndex; if (voiceIndex < 0) voiceIndex = 0; if (tokens.Count > 0) { spVoice.SetVoice((ISpObjectToken)tokens.Item(voiceIndex)); spVoice.Viseme += new _ISpeechVoiceEvents_VisemeEventHandler(voice_Viseme); spVoice.Speak(text, SpeechVoiceSpeakFlags.SVSFlagsAsync); } }
public MainWindow() { InitializeComponent(); ISpeechObjectTokens voices = sp.GetVoices(); foreach (ISpeechObjectToken item in voices) { ComboBoxItem comboBoxItem = new ComboBoxItem(); comboBoxItem.Content = item.GetDescription(); Speaker.Items.Add(comboBoxItem); } ComboBoxItem cbi = (Speaker.Items[0]) as ComboBoxItem; cbi.IsSelected = true; }
private void buttonOK_Click(object sender, EventArgs e) { tokens = spVoice.GetVoices("", ""); spVoice.SetVoice((ISpObjectToken)tokens.Item(0)); spMemoryStream = new SpMemoryStream(); SpAudioFormat spAudioFormat = new SpAudioFormat(); spAudioFormat.Type = waveType; spMemoryStream.Format = spAudioFormat; spVoice.AudioOutputStream = spMemoryStream; spVoice.EndStream += new _ISpeechVoiceEvents_EndStreamEventHandler(SpeechDone); spVoice.Viseme += new _ISpeechVoiceEvents_VisemeEventHandler(voice_Viseme); spVoice.Speak(textBoxSpeak.Text, SpeechVoiceSpeakFlags.SVSFlagsAsync); }
/// <summary> /// 设置语音 /// </summary> /// <param name="Rate"></param> /// <param name="Volume"></param> /// <param name="VoiceName"></param> public void SetVoice(int Rate, int Volume, string VoiceName) { voice.Rate = Rate; voice.Volume = Volume; ISpeechObjectTokens arrVoices = voice.GetVoices(); int index = 0; for (int i = 0; i < arrVoices.Count; i++) { if (arrVoices.Item(i).GetDescription() == VoiceName) { index = i; break; } } voice.Voice = voice.GetVoices().Item(index); }
private void Form1_Load(object sender, EventArgs e) { SpVoice spv = new SpVoice(); if (spv == null) { return; } ISpeechObjectTokens arrVoices = spv.GetVoices(string.Empty, string.Empty); List <string> arrlist = new List <string>(); for (int i = 0; i < arrVoices.Count; i++) { arrlist.Add(arrVoices.Item(i).GetDescription(0)); } cmbVoices.DataSource = arrlist; }
/// //Resources.Load('builtIn.xml') as Texture; /// PRINT ON SCREEN SAPI VOICES INSTALLED IN THE OS void OnGUI() { SpObjectTokenCategory tokenCat = new SpObjectTokenCategory(); tokenCat.SetId(SpeechLib.SpeechStringConstants.SpeechCategoryVoices, false); ISpeechObjectTokens tokens = tokenCat.EnumerateTokens(null, null); int n = 0; foreach (SpObjectToken item in tokens) { // GUILayout.Label( "Voice"+ n +" ---> "+ item.GetDescription(0)); n ++; } //GUILayout.Label( "There are "+ n +" SAPI voices installed in your OS | Press SPACE for start TEST"); //Set a voice (if not using XML) // voice.Voice = (tokens.Item (3)); // Comment this line if you use XML parser for choice voices, force a voice over the def one. }
public Speak(Conductor c, String text, int voiceIndex) { conductor = c; tokens = spVoice.GetVoices("", ""); //currentVoiceIndex = comboBoxVoice.SelectedIndex; if (voiceIndex < 0) { voiceIndex = 0; } if (tokens.Count > 0) { spVoice.SetVoice((ISpObjectToken)tokens.Item(voiceIndex)); spVoice.Viseme += new _ISpeechVoiceEvents_VisemeEventHandler(voice_Viseme); spVoice.Speak(text, SpeechVoiceSpeakFlags.SVSFlagsAsync); } }
public override void Initialize(TextToSpeechOptions ttsOptions) { if (ttsOptions.GetType() == typeof(SpeechLibTTSOptions)) { windowsTTSOptions = (SpeechLibTTSOptions)ttsOptions; SpObjectTokenCategory tokenCat = new SpObjectTokenCategory(); tokenCat.SetId(SpeechLib.SpeechStringConstants.SpeechCategoryVoices, false); ISpeechObjectTokens tokens = tokenCat.EnumerateTokens(null, null); spVoice = new SpVoice(); spVoice.Voice = tokens.Item(windowsTTSOptions.Voice); spVoice.Volume = windowsTTSOptions.Volume; spVoice.Rate = windowsTTSOptions.Rate; spFileStream = new SpFileStream(); } }
private void DrawVoicePopup() { SpObjectTokenCategory tokenCategory = new SpObjectTokenCategory(); tokenCategory.SetId(SpeechLib.SpeechStringConstants.SpeechCategoryVoices, false); ISpeechObjectTokens tokens = tokenCategory.EnumerateTokens(null, null); voices = new string[tokens.Count]; int n = 0; foreach (SpObjectToken item in tokens) { voices[n] = item.GetDescription(0); n++; } selection = EditorGUILayout.Popup(selection, voices, GUI.skin.GetStyle("customEnum")); serviceOptions.Voice = selection; }
}//public static void SpVoiceSpeak() ///<summary>SpeechObjectTokensVoices</summary> public static void SpeechObjectTokensVoices ( ref ISpeechObjectTokens speechObjectTokens, ref string exceptionMessage ) { SpVoice spVoice = null; try { spVoice = new SpVoice(); speechObjectTokens = spVoice.GetVoices("", ""); #if (DEBUG) foreach ( ISpeechObjectToken speechObjectToken in speechObjectTokens ) { System.Console.WriteLine("Voice: {0}", speechObjectToken.GetDescription(1033) ); } #endif }//try catch ( Exception exception ) { UtilityException.ExceptionLog( exception, exception.GetType().Name, ref exceptionMessage ); } }//public static ISpeechObjectTokens SpeechObjectTokensVoices()
private void Sound_Test_Form_Load(object sender, EventArgs e) { voice = new SpVoiceClass(); ISpeechObjectTokens spObjs = voice.GetVoices("", ""); int i = 0; foreach (ISpeechObjectToken spObj in spObjs) { this.comboBoxVoiceList.Items.Add(spObj.GetDescription(i++)); } settings = ModuleConfig.GetSettings(); try { this.comboBoxVoiceList.SelectedIndex = settings.VoiceIndex; } catch { } tmpIndex = settings.VoiceIndex; }
/// <summary> /// Simple TTS /// </summary> /// <param name="args">args[0]: Message, args[1]: Attributes e.g. "Language=409;Gender=Female"</param> static void Main(string[] args) { SpVoice voice = new SpVoice(); voice.Volume = 100; // Volume voice.Rate = 0; // Rate SpObjectTokenCategory tokenCat = new SpObjectTokenCategory(); tokenCat.SetId(SpeechLib.SpeechStringConstants.SpeechCategoryVoices, false); string requiredAttributes = null; if (args.Length > 1) { // Select tokens // (Language:409=English (United States)/411=Japanese, Gender:Male/Female ... ) requiredAttributes = args[1]; } ISpeechObjectTokens tokens = tokenCat.EnumerateTokens(requiredAttributes, null); // No tokens if (tokens.Count == 0) { // Reselect tokens = tokenCat.EnumerateTokens(null, null); // Get all tokens } voice.Voice = tokens.Item(0); string message = "Hello World!"; if (args.Length > 0) { message = args[0]; } voice.Speak(message, SpeechVoiceSpeakFlags.SVSFDefault); Console.WriteLine("Finished"); }
public ShowUdisk(string info, int ReciveCheckFlag) : base() { InitializeComponent(); SpVoice spv = new SpVoice(); if (spv == null) { return; } ISpeechObjectTokens arrVoices = spv.GetVoices(string.Empty, string.Empty); List <string> arrlist = new List <string>(); for (int i = 0; i < arrVoices.Count; i++) { arrlist.Add(arrVoices.Item(i).GetDescription(0)); } cmbVoices.DataSource = arrlist; Point p = new Point(500, 1024); this.Location = p; t = new byte[4]; t[0] = 5; label1.Text = info; if (ReciveCheckFlag == 1) { speak_Thread = new Thread(new ThreadStart(start_Speak)); speak_Thread.Start(); linkLabel1.Visible = true; linkLabel1.Text = "检测到可自执行文件,建议使用U盘防护扫描"; linkLabel1.LinkColor = Color.Red; } else { linkLabel1.Visible = false; } //linkLabel1.Text = "未检测到可自执行文件,\r建议使用U盘防护扫描"; }
private void SpeakToOutputDevice(string message, string language) { const SpeechVoiceSpeakFlags speechFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync; SpVoice synth = new SpVoice(); SpMemoryStream wave = new SpMemoryStream(); ISpeechObjectTokens voices = synth.GetVoices(); try { synth.Rate = 0; synth.Volume = 100; wave.Format.Type = SpeechAudioFormatType.SAFT44kHz16BitStereo; synth.AudioOutputStream = wave; if (language != null) { foreach (SpObjectToken voice in voices) { if (voice.GetAttribute("Name") == language) { synth.Voice = voice; } } } synth.Speak(message, speechFlags); synth.WaitUntilDone(Timeout.Infinite); OutputWaveStream(wave); } finally { Marshal.ReleaseComObject(voices); Marshal.ReleaseComObject(wave); Marshal.ReleaseComObject(synth); } }
public void Call(DmType dmtype, string callstring, double je, CFMX[] CFMX) { string patientName = "发 药 窗 口 "; patientName = patientName + callstring + " " + je.ToString(); string ssql = "select '' "; if (dmtype == DmType.发药呼叫) { try { string ss = "请" + CFMX[0].brxm + "到" + CFMX[0].fyck + "来取药"; SpVoiceClass class2 = new SpVoiceClass(); ISpeechObjectTokens voices = class2.GetVoices("Language = 804", "Gender = Female"); if (voices.Count > 0) { class2.Voice = voices.Item(0); class2.Speak(ss, SpeechVoiceSpeakFlags.SVSFDefault); } } catch (Exception exception) { } } if (dmtype == DmType.发药) { try { Display(patientName, Math.Abs(je)); } catch (Exception exception) { } } }
public Sound_Test_Form() { InitializeComponent(); voice = new SpVoiceClass(); spObjs = voice.GetVoices("", ""); }
private Speech() { voices = speech.GetVoices(); }
private void PrepareTextToSpeechAndGestures() { tokens = spVoice.GetVoices("", ""); for (int i = 0; i < tokens.Count; i++) { robotVoiceComboBox.Items.Add(tokens.Item(i).GetAttribute("Name")); } if (tokens.Count > 0) { robotVoiceComboBox.SelectedIndex = 0; } conductor.SetControls(ref robotStates, ref placeholderRecorder, ref placeholderSimulator); conductor.SetStates(ref robotStates); conductor.SetDistanceTrigger(false, false, false, 60); }
public TTSAppForm() { InitializeComponent(); System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(TTSAppForm)); try { Voice = new SpVoiceClass(); } catch (Exception) { // This might fail if the user does not have // Speech Automation 5.1 Runtimes installed. MessageBox.Show("An error has occurred while trying to initialize SAPI 5.1."); Application.Exit(); } // We're interested in all events, so hook them up. Voice.EventInterests = SpeechVoiceEvents.SVEAllEvents; Voice.AudioLevel += new _ISpeechVoiceEvents_AudioLevelEventHandler(this.Voice_AudioLevel); Voice.Bookmark += new _ISpeechVoiceEvents_BookmarkEventHandler(this.Voice_Bookmark); Voice.EndStream += new _ISpeechVoiceEvents_EndStreamEventHandler(this.Voice_EndStream); Voice.EnginePrivate += new _ISpeechVoiceEvents_EnginePrivateEventHandler(this.Voice_EnginePrivate); Voice.Phoneme += new _ISpeechVoiceEvents_PhonemeEventHandler(this.Voice_Phoneme); Voice.Sentence += new _ISpeechVoiceEvents_SentenceEventHandler(this.Voice_Sentence); Voice.StartStream += new _ISpeechVoiceEvents_StartStreamEventHandler(this.Voice_StartStream); Voice.Viseme += new _ISpeechVoiceEvents_VisemeEventHandler(this.Voice_Viseme); Voice.VoiceChange += new _ISpeechVoiceEvents_VoiceChangeEventHandler(this.Voice_VoiceChange); Voice.Word += new _ISpeechVoiceEvents_WordEventHandler(this.Voice_Word); // Populate the list of voices. ISpeechObjectTokens voices = Voice.GetVoices("", ""); foreach (ISpeechObjectToken token in voices) { VoiceCombo.Items.Add(token.GetDescription(0)); } // Populate the list of output devices. ISpeechObjectTokens outputs = Voice.GetAudioOutputs("", ""); foreach (ISpeechObjectToken token in outputs) { OutputCombo.Items.Add(token.GetDescription(0)); } // This is better than what has been done in the // Microsoft samples. string[] formats = Enum.GetNames(typeof(SpeechAudioFormatType)); for (int i = 0; i < formats.Length; i++) { FormatCombo.Items.Add(formats[i]); } // Load the talking microphone images. I have swiped // these directly from the Microsoft CPP sample. this.MicImages = new ImageList(); this.MicImages.TransparentColor = Color.Fuchsia; this.MicImages.ColorDepth = ColorDepth.Depth24Bit; this.MicImages.ImageSize = new Size(128, 128); this.MicImages.Images.Add((Bitmap)resources.GetObject("mic.bmp")); this.MicImages.Images.Add((Bitmap)resources.GetObject("mic_mouth_2.bmp")); this.MicImages.Images.Add((Bitmap)resources.GetObject("mic_mouth_3.bmp")); this.MicImages.Images.Add((Bitmap)resources.GetObject("mic_mouth_4.bmp")); this.MicImages.Images.Add((Bitmap)resources.GetObject("mic_mouth_5.bmp")); this.MicImages.Images.Add((Bitmap)resources.GetObject("mic_mouth_6.bmp")); this.MicImages.Images.Add((Bitmap)resources.GetObject("mic_mouth_7.bmp")); this.MicImages.Images.Add((Bitmap)resources.GetObject("mic_mouth_8.bmp")); this.MicImages.Images.Add((Bitmap)resources.GetObject("mic_mouth_9.bmp")); this.MicImages.Images.Add((Bitmap)resources.GetObject("mic_mouth_10.bmp")); this.MicImages.Images.Add((Bitmap)resources.GetObject("mic_mouth_11.bmp")); this.MicImages.Images.Add((Bitmap)resources.GetObject("mic_mouth_12.bmp")); this.MicImages.Images.Add((Bitmap)resources.GetObject("mic_mouth_13.bmp")); this.MicImages.Images.Add((Bitmap)resources.GetObject("mic_eyes_closed.bmp")); this.MicImages.Images.Add((Bitmap)resources.GetObject("mic_eyes_narrow.bmp")); this.MouthPicture.Image = MicImages.Images[0]; this.VolumeSlider.Value = Voice.Volume; this.RateSlider.Value = Voice.Rate; InputTextBox.ReadOnly = false; SkipButton.Enabled = false; SpeakButton.Enabled = true; PauseResumeButton.Enabled = false; StopButton.Enabled = false; this.InputTextBox.Focus(); }
private void InsertTextToSpeech_Load(object sender, EventArgs e) { tokens = spVoice.GetVoices("", ""); for (int i = 0; i < tokens.Count; i++) comboBoxVoice.Items.Add(tokens.Item(i).GetAttribute("Name")); if (tokens.Count>0) comboBoxVoice.SelectedIndex = 0; }
public MainWindow() { InitializeComponent(); TextLogger logger = TextLogger.instance; logger.output = logTextBox; /** * Initialize log4net */ string log4netPath = "log4net/log4net.config"; if (File.Exists(log4netPath)) { XmlConfigurator.Configure(new FileInfo(log4netPath)); } else if (File.Exists(Environment.ExpandEnvironmentVariables("%APPDATA%") + "/EliteVoice/" + log4netPath)) { XmlConfigurator.Configure(new FileInfo(Environment.ExpandEnvironmentVariables("%APPDATA%") + "/EliteVoice/" + log4netPath)); } else { logger.log("Not found log4net configuration. See documentation."); } var enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator(); var dev = enumerator.GetDefaultAudioEndpoint(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.Role.Console); //logger.log(dev.DeviceFriendlyName); //logger.log(dev.FriendlyName); speech = Speech.instance; //speech.speech. audios = speech.speech.GetAudioOutputs(); int idx = 0, i = 0; foreach (SpObjectToken audio in audios) { audioDevices.Items.Add(audio.GetDescription()); //if (audio.GetDescription().Equals(speech.speech.AudioOutput.GetDescription())) if (audio.GetDescription().Equals(dev.FriendlyName)) { speech.speech.AudioOutput = audio; idx = i; } i++; } audioDevices.SelectedIndex = idx; /* * */ logger.log("Found voices:"); foreach (ISpeechObjectToken voice in speech.speech.GetVoices()) { logger.log(voice.GetDescription()); } /** * */ EliteVoice.ConfigReader.ConfigReader config = null; string configPath = "config/config.xml"; if (File.Exists(configPath)) { config = new EliteVoice.ConfigReader.ConfigReader(configPath); } else if (File.Exists(Environment.ExpandEnvironmentVariables("%APPDATA%") + "/EliteVoice/" + configPath)) { config = new EliteVoice.ConfigReader.ConfigReader(Environment.ExpandEnvironmentVariables("%APPDATA%") + "/EliteVoice/" + configPath); } else { logger.log("Not found configuration!!!"); return; } config.parse(); /* * */ commands = new CommandProcessor(config); List <FileDescription> files = new List <FileDescription>(); fileGrid.ItemsSource = files; FileProcessor processor = new FileProcessor(files, commands); tProcessor = new Thread(new ThreadStart(processor.directoryRead)); tProcessor.Start(); lProcessor = new Thread(new ThreadStart(processor.processCurrentFile)); lProcessor.Start(); }
/// <summary> /// Adds the user's installed SAPI-compliant SpeechRecognizers (speech /// recognition engines) to a specified combobox. /// </summary> /// <param name="co"></param> /// <returns>true if a Recognizer was found and added to the list; /// false if user is SoL</returns> internal static bool AddSpeechRecognizers(ComboBox co) { #if DEBUG logfile.Log(); logfile.Log("SpeechRecognizerLister.AddSpeechRecognizers()"); logfile.Log(". create (SpInprocRecognizer)_recognizer"); #endif // NOTE: This is your SAPI5.4 SpeechRecognizer (aka SpeechRecognitionEngine) interface. // good luck! var sr_default = new SpInprocRecognizer(); #if DEBUG logfile.Log(". (SpInprocRecognizer)_recognizer CREATED"); #endif if (sr_default != null) { #if DEBUG logfile.Log(); logfile.Log("Recognizer.Id= " + sr_default.Recognizer.Id); logfile.Log("Recognizer.GetDescription()= " + sr_default.Recognizer.GetDescription()); logfile.Log(); #endif ISpeechObjectTokens toks = sr_default.GetRecognizers(); #if DEBUG foreach (ISpeechObjectToken tok in toks) { logfile.Log(". installed.Id= " + tok.Id); logfile.Log(". installed.GetDescription()= " + tok.GetDescription()); } logfile.Log(); #endif int id_default = -1; bool id_default_found = false; var recognizers = new List <Recognizer>(); foreach (ISpeechObjectToken tok in toks) { if (tok.GetDescription().Contains("Microsoft Speech Recognizer")) // 8.0+ TODO: other SAPI-compliant speech engines incl/ 3rd-party { recognizers.Add(new Recognizer(tok)); if (!id_default_found) { ++id_default; if (tok.Id == sr_default.Recognizer.Id) { id_default_found = true; } } } } if (recognizers.Count != 0) { co.DataSource = recognizers; co.SelectedIndex = id_default; return(true); } } #if DEBUG logfile.Log(". RECOGNIZER NOT FOUND"); #endif return(false); }
/// <summary> /// Creates an audio representation of the current access code. /// </summary> /// <returns>A byte array of an PCM Wave audio form.</returns> public byte[] GenerateAudio() { #if MONO throw new NotImplementedException(); #else try { Random rnd = new Random(); string toSpeak = string.Empty; foreach (char c in AccessCode.ToCharArray()) { toSpeak += c.ToString() + ". "; } string tempPath = Path.GetTempPath(); if (!tempPath.EndsWith("\\")) { tempPath += "\\"; } string tempFile = tempPath + "sound" + Guid.NewGuid().ToString() + ".wav"; //we don't know why memorystream does not work. SpFileStream stream = null; try { stream = new SpFileStream(); stream.Open(tempFile, SpeechStreamFileMode.SSFMCreateForWrite, false); SpVoice speech = new SpVoice(); ISpeechObjectTokens voices = speech.GetVoices(string.Empty, string.Empty); if (voices == null) { throw new TenorException("No available voices."); } speech.Voice = voices.Item(rnd.Next(0, (int)voices.Count)); //Dim format As New SpAudioFormat //format.Type = SpeechAudioFormatType.SAFTGSM610_11kHzMono //sound.Format = format speech.AudioOutputStream = (ISpeechBaseStream)stream; speech.Rate = -2; //from -10 to +10 //speaks to the stream speech.Speak(toSpeak, SpeechVoiceSpeakFlags.SVSFlagsAsync); speech.WaitUntilDone(-1); speech = null; voices = null; } catch (Exception ex) { try { if (System.IO.File.Exists(tempFile)) { System.IO.File.Delete(tempFile); } } catch (Exception) { } throw ex; } finally { try { if (stream != null) { stream.Close(); } stream = null; } catch (Exception) { } } byte[] bytes = null; try { if (System.IO.File.Exists(tempFile)) { System.IO.FileStream file = new System.IO.FileStream(tempFile, System.IO.FileMode.Open); bytes = Tenor.IO.BinaryFile.StreamToBytes(file); file.Close(); System.IO.File.Delete(tempFile); } } catch { } return(bytes); } catch (Exception ex) { throw new TenorException("Cannot generate the audio tag. This server may not have the Ms Speech API.", ex); } #endif }