Beispiel #1
0
        private void InitSpeech()
        {
            try
            {
                speechSynthesizer = new SpeechSynthesizer();
                speechSynthesizer.SetOutputToDefaultAudioDevice();
                //speechSynthesizer.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(speechSynthesizer_SpeakCompleted);
                //speechSynthesizer.SpeakProgress += new EventHandler<SpeakProgressEventArgs>(speechSynthesizer_SpeakProgress);

                var voices = speechSynthesizer.GetInstalledVoices();
                foreach (var voice in voices)
                {
                    installedVoices.Add(voice.VoiceInfo.Culture.ToString().ToLower(), voice.VoiceInfo);
                }

                spVoice = new SpVoiceClass();
                spVoice.SetVolume(0);
                spVoice.SetPriority(SPVPRIORITY.SPVPRI_OVER);
                spVoice.StartStream += new _ISpeechVoiceEvents_StartStreamEventHandler(spVoice_StartStream);
                spVoice.EndStream   += new _ISpeechVoiceEvents_EndStreamEventHandler(spVoice_EndStream);
                spVoice.Viseme      += new _ISpeechVoiceEvents_VisemeEventHandler(spVoice_Viseme);
            }
            catch (Exception ex)
            {
                Trace.Write(ex.ToString());
            }
        }
Beispiel #2
0
        public void Speak(string t)
        {
            string  txt   = t;
            SpVoice voice = new SpVoiceClass();

            voice.Speak(txt, SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
        }
Beispiel #3
0
        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);
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            SpVoiceClass X = new SpVoiceClass();

            X.Speak("Hello World", 0);
            ISpVoice Y = (ISpVoice)X;
        }
Beispiel #5
0
        /// <summary>
        /// TTS文字转语音,传入需要转换的文本
        /// </summary>
        /// <param name="text">需要转语音的文本</param>
        public static void Speak(string text)
        {
            SpVoiceClass voice = new SpVoiceClass();

            voice.Volume = user.volume;
            voice.Voice  = voice.GetVoices(string.Empty, string.Empty).Item(0);
            voice.Speak(text, SpeechVoiceSpeakFlags.SVSFDefault);
        }
        void GetStatus(SpVoiceClass voice)
        {
            if (voice == null)
            {
                return;
            }

            SPVOICESTATUS status;
            string        bookmark;

            voice.GetStatus(out status, out bookmark);
            print(status.ulInputWordPos + " / " + status.ulInputWordPos + " / " + status.ulInputSentLen);
        }
Beispiel #7
0
 public static void SpeechChinese(string txt)
 {
     try
     {
         SpVoiceClass voice = new SpVoiceClass();
         voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);//Item(0)中文女聲
         voice.Speak(txt, SpeechVoiceSpeakFlags.SVSFDefault);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Beispiel #8
0
 public static void SpeechEnglish(string txt)
 {
     try
     {
         SpVoiceClass voice = new SpVoiceClass();
         voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(1);
         voice.Speak(txt, SpeechVoiceSpeakFlags.SVSFlagsAsync);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Beispiel #9
0
        public void txtToFile(string value, string fileName)
        {
            GC.Collect();
            SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;

            SpeechLib.SpVoice    voice        = new SpVoiceClass();
            SpeechStreamFileMode SpFileMode   = SpeechStreamFileMode.SSFMCreateForWrite;
            SpFileStream         SpFileStream = new SpFileStream();

            SpFileStream.Open(fileName, SpFileMode, false);
            voice.AudioOutputStream = SpFileStream;
            voice.Speak(value, SpFlags);
            voice.WaitUntilDone(System.Threading.Timeout.Infinite);
            SpFileStream.Close();
        }
Beispiel #10
0
        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;
        }
Beispiel #11
0
        /// <summary>
        /// 语音播放
        /// </summary>
        public static void NewRead()
        {
            try
            {
                //读取已有文件
                string            wavPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Sounds\\ring.wav";//要读的音频文件地址
                SpVoiceClass      pp      = new SpVoiceClass();
                SpFileStreamClass spFs    = new SpFileStreamClass();
                spFs.Open(wavPath, SpeechStreamFileMode.SSFMOpenForRead, true);
                ISpeechBaseStream Istream = spFs as ISpeechBaseStream;

                //文字转语音播放
                SpeechVoiceSpeakFlags spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
                SpVoice spVoice = new SpVoice();                                                                                  //声源
                spVoice.Rate   = Convert.ToInt32(System.Configuration.ConfigurationManager.ConnectionStrings["Rate"].ToString()); //速度
                spVoice.Volume = 100;
                spVoice.WaitUntilDone(-1);
                spVoice.SpeakStream(Istream, spFlags);
                //循环播放
                for (int i = 0; i < readCount; i++)
                {
                    spVoice.WaitUntilDone(-1);
                    spVoice.Speak(readTxt, spFlags);//文字转语音播放
                }
                spFs.Close();
                //直接读取音频文件
                //SoundPlayer soundPlayer = new SoundPlayer();
                //soundPlayer.SoundLocation = wavPath;
                //soundPlayer.Load();
                //soundPlayer.Play();
            }
            catch (Exception err)
            {
                MessageBox.Show("语音播报失败!");
                CommonalityEntity.WriteTextLog(err.ToString());
            }
        }
Beispiel #12
0
        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)
                {
                }
            }
        }
Beispiel #13
0
 private void LlamadaPrueba_Load(object sender, EventArgs e)
 {
     int x = 0, y = 0;
     voces = new SpObjectToken[30];
     audioOuts = new SpObjectToken[30];
     tapi.Initialize();
     //voice = new SpVoice();
     voz = new SpVoiceClass();
     foreach (TAddress addr in tapi.Addresses)
     {
         if ((addr.MediaTypes & TAPIMEDIATYPES.AUDIO) != 0)
             cbSalidas.Items.Add(addr);
     }
     foreach (SpObjectToken tok in voz.GetVoices("", ""))
     {
         voces[x++] = tok;
         cbVoces.Items.Add(tok.GetDescription(1033));
     }
     foreach (SpObjectToken tok in voz.GetAudioOutputs("", ""))
     {
         audioOuts[y++] = tok;
         cbAudioOuts.Items.Add(tok.GetDescription(1033));
     }
     cbVoces.SelectedIndex = 0;
     cbAudioOuts.SelectedIndex = 0;
     cbSalidas.SelectedIndex = 0;
 }
Beispiel #14
0
 public void txtToSpeech(string value)
 {
     GC.Collect();
     SpeechLib.SpVoice voice = new SpVoiceClass();
     voice.Speak(value, SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
 }
Beispiel #15
0
 public Sound_Test_Form()
 {
     InitializeComponent();
     voice  = new SpVoiceClass();
     spObjs = voice.GetVoices("", "");
 }
 void InitTTS()
 {
     voice        = new SpVoiceClass();
     voice.Volume = 100;
     voice.Rate   = 1;
 }
Beispiel #17
0
        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();
        }
Beispiel #18
0
        private void Main_Load(object sender, EventArgs e)
        {
            Autorizate autorizate = new Autorizate();

            autorizate.ShowDialog();

            FbConnectionStringBuilder sb = new FbConnectionStringBuilder(Properties.Settings.Default.TaxiConnectionString);

            sb.UserID   = autorizate.UserID;
            sb.Password = autorizate.Password;
            sb.Role     = Convert.ToString(autorizate.Role);
            Properties.Settings.Default["TaxiConnectionString"] = sb.ConnectionString;          //Замена параметров в connectionstring
            FbConnection test = new FbConnection(sb.ToString());

            try
            {
                //string role = "operator";       //UTF8 -> win1251
                if (sb.Role == "admins")        ///-----
                {
                    test.Open();
                    test.Close();
                    Admin medic = new Admin();      //Окрытие интерфейса admin
                    ShowChildForm(medic, this);
                    AutorizateStatus = true;
                    UserStatus       = "admin";
                }
                else if (sb.Role == "operator")        ///-----
                {
                    test.Open();
                    test.Close();
                    newMdiChild = new Operator();      //Окрытие интерфейса оператора
                    ShowChildForm(newMdiChild, this);
                    AutorizateStatus = true;
                    UserStatus       = "operator";
                }
                else if (sb.Role == "medic")
                {
                    test.Open();
                    test.Close();
                    Medic newMdiChild = new Medic();      //Окрытие интерфейса медика
                    ShowChildForm(newMdiChild, this);
                    AutorizateStatus = true;
                    UserStatus       = "medic";
                }
                else if (sb.Role == "technic")
                {
                    test.Open();
                    test.Close();
                    Technic newMdiChild = new Technic();
                    ShowChildForm(newMdiChild, this);
                    AutorizateStatus = true;
                    UserStatus       = "technic";
                }
            }
            catch (Exception ex)
            {
                SpVoiceClass voice = new SpVoiceClass();
                string       str   = "Перелогиньтесь";
                voice.Speak(str, SpeechVoiceSpeakFlags.SVSFlagsAsync);
                MessageBox.Show(str + ". " + ex.Message);
            }
        }
Beispiel #19
0
 static void Speak(string text)
 {
     SpVoice voice = new SpVoiceClass();
     voice.Speak(text, SpeechVoiceSpeakFlags.SVSFDefault);
 }