示例#1
0
        public  static bool SpeechInitialize(IntPtr win, string voice)
        {
            try
            {
                m_Speak = true;

                m_SPV = new SpVoice();
                if (!string.IsNullOrEmpty(voice))
                {
                    ISpeechObjectTokens voices = m_SPV.GetVoices("", "");
                    foreach (ISpeechObjectToken v in voices)
                    {
                        if (v.GetDescription(0) == voice)
                        {
                            m_SPV.Voice = (SpObjectToken)v;
                            break;
                        }
                    }
                }
                else if (voice == null)
                    m_Speak = false;

                return true;
            }
            catch {
                return false;
            }
        }
		/// <summary>Speaks the specified text to the specified file.</summary>
		/// <param name="text">The text to be spoken.</param>
		/// <param name="audioPath">The file to which the spoken text should be written.</param>
		/// <remarks>Uses the Microsoft Speech libraries.</remarks>
		private void SpeakToFile(string text, FileInfo audioPath)
		{
			SpFileStream spFileStream = new SpFileStream();
			try
			{
				// Create the speech engine and set it to a random installed voice
				SpVoice speech = new SpVoice();
				ISpeechObjectTokens voices = speech.GetVoices(string.Empty, string.Empty);
				speech.Voice = voices.Item(NextRandom(voices.Count));

				// Set the format type to be heavily compressed.  This both decreases download
				// size and increases distortion.
				SpAudioFormatClass format = new SpAudioFormatClass();
				format.Type = SpeechAudioFormatType.SAFTGSM610_11kHzMono;
				spFileStream.Format = format;

				// Open the output stream for the file, speak to it, and wait until it's complete
				spFileStream.Open(audioPath.FullName, SpeechStreamFileMode.SSFMCreateForWrite, false);
				speech.AudioOutputStream = spFileStream;
				speech.Speak(text, SpeechVoiceSpeakFlags.SVSFlagsAsync);
				speech.Rate = -5;
				speech.WaitUntilDone(System.Threading.Timeout.Infinite);
			}
			finally
			{
				// Close the output file
				spFileStream.Close();
			}
		}
示例#3
0
        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;
        }
示例#4
0
 public Form1()
 {
     InitializeComponent();
     voice = new SpVoice();
     foreach (ISpeechObjectToken Token in voice.GetVoices(string.Empty, string.Empty))
     {
         cmbVoices.Items.Add(Token.GetDescription(49));
     }
     cmbVoices.SelectedIndex = 0;
     // Not sure how to set voice from this...
 }
 private void init_vox()
 {
     Vox = new SpVoice();
     var voices = Vox.GetVoices();
     voiceNames = new string[voices.Count];
     for (int i = 0; i < voices.Count; i++)
     {
         var voice = voices.Item(i);
         var name = voice.GetDescription();
         voiceNames[i] = name;
     }
     Vox.Word += Vox_Word;
     Vox.EndStream += Vox_EndStream;
 }
示例#6
0
        public void speak(object source, ElapsedEventArgs e)
        {
            DataSet ds  = new DataSet();
            string  sql = "select * from line";

            ds = sqlHelper.ExecuteDataSet(sql);
            SpeechVoiceSpeakFlags flag = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            SpVoice voice     = new SpVoice();
            string  b         = ds.Tables[0].Rows[0]["id"].ToString();
            string  voice_txt = string.Format("Please register for number {0} ", b);

            voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
            voice.Speak(voice_txt, flag);
            timer.Stop();
        }
示例#7
0
        public static byte[] GetSound(string text)
        {
            const SpeechVoiceSpeakFlags speechFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            var synth  = new SpVoice();
            var wave   = new SpMemoryStream();
            var voices = synth.GetVoices();

            try
            {
                // synth setup
                synth.Volume = 100;
                synth.Rate   = -3;
                foreach (SpObjectToken voice in voices)
                {
                    if (voice.GetAttribute("Name") == "Microsoft Matej")
                    {
                        synth.Voice = voice;
                        break;
                    }
                }

                wave.Format.Type        = SpeechAudioFormatType.SAFT22kHz16BitMono;
                synth.AudioOutputStream = wave;
                synth.Speak(text, speechFlags);
                synth.WaitUntilDone(Timeout.Infinite);

                var waveFormat = new WaveFormat(22050, 16, 1);
                using (var ms = new MemoryStream((byte[])wave.GetData()))
                    using (var reader = new RawSourceWaveStream(ms, waveFormat))
                        using (var outStream = new MemoryStream())
                            using (var writer = new WaveFileWriter(outStream, waveFormat))
                            {
                                reader.CopyTo(writer);
                                //return o.Mp3 ? ConvertToMp3(outStream) : outStream.GetBuffer();

                                //var bytes = ConvertToMp3(outStream);
                                File.WriteAllBytes("speak.wav", outStream.GetBuffer());

                                return(null);
                            }
            }
            finally
            {
                Marshal.ReleaseComObject(voices);
                Marshal.ReleaseComObject(wave);
                Marshal.ReleaseComObject(synth);
            }
        }
        public JsonResult GetVoice(string des)
        {
            string str = Strings.StrConv(des, Microsoft.VisualBasic.VbStrConv.SimplifiedChinese, 0x0804);

            SpeechLib.SpVoice voice = new SpVoice();
            voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
            if (des != "0")
            {
                voice.Speak(str, SpeechVoiceSpeakFlags.SVSFlagsAsync);
            }
            else
            {
                voice.Pause();
            }
            return(Json(""));
        }
示例#9
0
        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;
        }
示例#10
0
 public static string Speek(string word)
 {
     string url;
     if (!CheckWord(word, out url))
     {
         var path = HttpContext.Current.Server.MapPath(url);
         var voice = new SpVoice();
         voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
         var sp = new SpFileStream();
         sp.Open(path, SpeechStreamFileMode.SSFMCreateForWrite);
         voice.AudioOutputStream = sp;
         voice.Speak(word);
         voice.WaitUntilDone(System.Threading.Timeout.Infinite);
         sp.Close();
     }
     return url;
 }
示例#11
0
        public CrossingDetectorExperiment()
        {
            InitializeComponent();

            dir                          = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
            houghLineViewer              = new ImageViewer();
            houghLineViewer.FormClosing += houghLineViewer_FormClosing;

            voice       = new SpVoice();
            voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);//Item(0)中文女聲


            //ScanLine的各線段
            crossingConnectionlines            = new List <LineSegment2DF>();
            candidateZebraCrossingsByHoughLine = new List <LineSegment2D>();


            candiateLineEquation_i = 0;
            candiateLineEquation_j = candiateLineEquation_i + 1;

            repairedHoughLine = new List <LineSegment2D>();

            //非步驟
            candidateHoughLineEquations         = new LinkedList <LineEquation>();
            repairedHoughLineViwer              = new ImageViewer();
            repairedHoughLineViwer.FormClosing += repairedHoughLineViwer_FormClosing;

            //步驟
            //初始化 修復線段步驟的修復圖
            searchRepairHoughLineStepViewer              = new ImageViewer();
            searchRepairHoughLineStepViewer.FormClosing += searchRepairHoughLineStepViewer_FormClosing;
            //初始化 修復線段步驟的尋找可否修復圖
            repairedHoughLineStepViewer              = new ImageViewer();
            repairedHoughLineStepViewer.FormClosing += repairHoughLineViewer_FormClosing;

            candidateHoughLineEquationsForReplay = new List <LineEquation>();

            linesHistogram = new Dictionary <CrossingDetector.LineQuantification, LinkedList <LineEquation> >();


            //video
            testVideoTimer  = new Timer();
            videoTotalFrame = 0;
            isPlay          = isStop = false;
            isVideoZebra    = false;
        }
        /// <summary>
        /// 设置当前使用语音库
        /// </summary>
        /// <returns>bool</returns>
        private bool setDescription(string name)
        {
            List <string> list = new List <string>();

            DotNetSpeech.ISpeechObjectTokens obj = voice.GetVoices();
            int count = obj.Count;//获取语音库总数

            for (int i = 0; i < count; i++)
            {
                string desc = obj.Item(i).GetDescription(); //遍历语音库
                if (desc.Equals(name))
                {
                    voice.Voice = obj.Item(i);
                    return(true);
                }
            }
            return(false);
        }
示例#13
0
        private void MonitorSpeak()
        {
            SpVoice spv = new SpVoice();

            if (spv == null)
            {
                return;
            }

            spv.Voice  = spv.GetVoices(string.Empty, string.Empty).Item(cmbVoices.SelectedIndex);
            spv.Volume = 100;

            spv.Speak(sendString, SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault);

            speak_Thread.Abort();
            speak_Thread.Join();
            speak_Thread = null;
        }
示例#14
0
        public static string SpeekToFile(string word)
        {
            string url;

            if (!CheckWord(word, out url))
            {
                var path  = Utils.GetCurrentDir() + url;
                var voice = new SpVoice();
                voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
                var sp = new SpFileStream();
                sp.Open(path, SpeechStreamFileMode.SSFMCreateForWrite);
                voice.AudioOutputStream = sp;
                voice.Speak(word);
                voice.WaitUntilDone(System.Threading.Timeout.Infinite);
                sp.Close();
            }
            return(url);
        }
示例#15
0
 public static void Ts()//按时提示
 {
     while (true)
     {
         if (DateTime.Now.Minute == 00 || DateTime.Now.Minute == 30 && DateTime.Now.Second == 00)
         {
             double  sj    = double.Parse(Function.WorkTime) / 60;
             SpVoice voice = new SpVoice();
             voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
             if (sj > 4)
             {
                 voice.Speak("亲爱的您已使用电脑" + Math.Floor(sj) + "个多小时了!请注意休息,累坏了人家会心疼的呢!", SpeechVoiceSpeakFlags.SVSFDefault);
             }
         }
         if (DateTime.Now.Hour == 7 && DateTime.Now.Minute == 00 && DateTime.Now.Second == 00)
         {
             SpVoice voice = new SpVoice();
             voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
             voice.Speak("亲爱的现在已经7点了记得吃早餐啊!", SpeechVoiceSpeakFlags.SVSFDefault);
             continue;
         }
         if (DateTime.Now.Hour == 11 && DateTime.Now.Minute == 00 && DateTime.Now.Second == 00)
         {
             SpVoice voice = new SpVoice();
             voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
             voice.Speak("亲爱的现在已经11点了记得吃午饭哦!", SpeechVoiceSpeakFlags.SVSFDefault);
             continue;
         }
         if (DateTime.Now.Hour == 18 && DateTime.Now.Minute == 00 && DateTime.Now.Second == 00)
         {
             SpVoice voice = new SpVoice();
             voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
             voice.Speak("亲爱的现在已经晚上6点了快去吃晚饭呀!", SpeechVoiceSpeakFlags.SVSFDefault);
             continue;
         }
         if (DateTime.Now.Hour == 23 && DateTime.Now.Minute == 00 && DateTime.Now.Second == 00)
         {
             SpVoice voice = new SpVoice();
             voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
             voice.Speak("亲爱的现在已经晚上11点了还不快去睡觉!!!", SpeechVoiceSpeakFlags.SVSFDefault);
             continue;
         }
     }
 }
示例#16
0
        public static void InitNeoSpeechVoices()
        {
            NeoSpeechVoices = new Dictionary<NeoSpeechVoiceType,SpObjectToken>();
            try
            {
                Dictionary<NeoSpeechVoiceType, SpObjectToken> ObjectTokens = new Dictionary<NeoSpeechVoiceType, SpObjectToken>();
                var voice = new SpVoice();

                string[] speakers = { "VW Julie", "VW Kate", "VW Paul", "VW Liang", "VW Hui", "Microsoft Lili - Chinese (China)", "Microsoft Anna - English (United States)" };

                NeoSpeechVoiceType speaker = NeoSpeechVoiceType.Julie;
                ISpeechObjectTokens sot = voice.GetVoices(string.Empty, string.Empty);
                string[] voiceIds = new string[sot.Count];
                for (int i = 0; i < sot.Count; i++)
                {
                    voiceIds[i] = sot.Item(i).GetDescription(1033);
                    if (speakers.Contains(voiceIds[i]))
                    {
                        switch (voiceIds[i])
                        {
                            case "VW Julie": speaker = NeoSpeechVoiceType.Julie; break;
                            case "VW Kate": speaker = NeoSpeechVoiceType.Kate; break;
                            case "VW Paul": speaker = NeoSpeechVoiceType.Paul; break;
                            case "VW Liang": speaker = NeoSpeechVoiceType.Liang; break;
                            case "VW Hui": speaker = NeoSpeechVoiceType.Hui; break;
                            case "Microsoft Lili - Chinese (China)": speaker = NeoSpeechVoiceType.Lili; break;
                            case "Microsoft Anna - English (United States)": speaker = NeoSpeechVoiceType.Anna; break;
                            default: speaker = NeoSpeechVoiceType.Julie; break;
                        }
                        ObjectTokens.Add(speaker, sot.Item(i));
                    }
                }
                NeoSpeechVoices = ObjectTokens;
            }
            catch(Exception ex)
            {
                string path = MainForm.AppPath + "\\log";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                File.AppendAllText(path + "\\log" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", ex.Message + "\n\r");
            }
        }
示例#17
0
        /// <summary>
        /// 开始转换
        /// </summary>
        public void Convert()
        {
            SpFileStream  sr    = new SpFileStream();
            SpAudioFormat audio = new SpAudioFormat();

            audio.Type = Format;
            sr.Format  = audio;
            sr.Open(SaveFileName, SpeechStreamFileMode.SSFMCreateForWrite, false);

            SpVoice voice = new SpVoice();

            voice.Voice             = voice.GetVoices(null, null).Item(0);//语言设置
            voice.Rate              = Rate;
            voice.AudioOutputStream = sr;
            voice.Volume            = Volume == 0 ? 100 : Volume;
            voice.Speak(InputText, SpeechVoiceSpeakFlags.SVSFlagsAsync);
            voice.WaitUntilDone(Timeout.Infinite);
            sr.Close();
        }
示例#18
0
        private void button2_Click(object sender, EventArgs e)
        {
            // 読み上げ中かどうかを判断
            if (sv.Status.RunningState == SpeechRunState.SRSEIsSpeaking)
            {
                // 読み上げ中なら停止
                sv.Speak(" ", SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
            }
            else
            {
                // 読み上げ対象文字列
                string str = ResultLabel.Text;

                // 空文字ならば読み上げない
                if (string.IsNullOrEmpty(str))
                {
                    return;
                }

                bool hit = false;
                foreach (SpObjectToken vp in sv.GetVoices())
                {
                    string lang = vp.GetAttribute("Language");

                    if (lang == "809" || lang == "409")
                    {
                        sv.Voice = vp;
                        hit      = true;
                    }
                }

                if (hit)
                {
                    sv.Rate   = _RateTrackBar.Value;
                    sv.Volume = _VolumeTrackBar.Value;
                    sv.Speak(ResultLabel.Text, SpeechVoiceSpeakFlags.SVSFlagsAsync);
                }
                else
                {
                    MessageBox.Show("英語合成音声が利用できません。\r\nMicrosoft Speech PlatformよりMSSpeech_SR_en-US_TELEを インストールしてください。\r\n");
                }
            }
        }
示例#19
0
        private void btnSpeak_Click(object sender, EventArgs e)
        {
            if (cboVoice.SelectedIndex == -1)
            {
                return;
            }
            SpVoice      oVoice       = new SpVoice();
            SpFileStream cpFileStream = new SpFileStream();

            oVoice.Voice  = oVoice.GetVoices().Item(cboVoice.SelectedIndex);
            oVoice.Volume = trVolume.Value;
            oVoice.Rate   = trRate.Value;
            oVoice.Speak(txtSpeak.Text, SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault);
            ////SpeechSynthesizer s = new SpeechSynthesizer();
            //SpVoice s = new SpVoice();
            //s.Speak("my name is Phu");
            ////s.Speak("Hello. My name is Microsoft Server Speech Text to Speech Voice (en-US, Helen).");
            //ISpeechRecoContext catchText = new SpInProcRecoContext();
        }
示例#20
0
        private void InvokeFirstMove()
        {
            if (!CheckCenterOccupied())
            {
                MessageBox.Show("The center of the board must be occupied", Application.ProductName);
                return;
            }


            /* Now we check if the word is put correctly on board
             * (must be put either horizontally or vertically) */

            if (!CheckWordPutCorrectly())
            {
                MessageBox.Show("The word must be put either horizontally or vertically , and without spaces", Application.ProductName);
                return;
            }


            string wordPut = GetWordPut();


            if (CheckWordFound(wordPut))   // word was found in dictionary
            {
                if (isSpeakLegalWords)
                {
                    SpVoice objSpeak = new SpVoice();

                    objSpeak.Voice = objSpeak.GetVoices("", "").Item(0);     // Microsoft Anna
                    objSpeak.Speak(wordPut.ToLower(), SpeechVoiceSpeakFlags.SVSFDefault);
                }

                score = GetWordPoints(wordPut);

                isStillFirstMove = false;
            }

            else    // word was not found in dictionary
            {
                MessageBox.Show("'" + wordPut.ToLower() + "' " + "is not a word.", Application.ProductName);
            }
        }
示例#21
0
        public void SpeakTxt(bool iscycle = false)
        {
            speech.Rate   = ProdConst.SRate;            //语速  介于-10于10之间
            speech.Volume = 100;
            speech.Voice  = speech.GetVoices().Item(0); //0-中文,1-英文。

            while (true)
            {
                for (int i = 0; i < righttxtdt.Rows.Count; i++)
                {
                    //SVSFlagsAsync异步播放。
                    speech.Speak(righttxtdt.Rows[i]["txt"].ToString(),
                                 SpeechVoiceSpeakFlags.SVSFlagsAsync);
                }
                if (iscycle == false)
                {
                    break;
                }
            }
        }
示例#22
0
 }//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()
示例#23
0
        private void btSave_Click(object sender, EventArgs e)
        {
            if(txtSpeach.Text == "")
            {
                CustomMessageBox.CustomMessageBox.Show("文本无内容,无法保存","错误",CustomMessageBox.CustomMessageBox.MsgBoxButtons.OK,CustomMessageBox.CustomMessageBox.MsgBoxIcons.Error);
                return;
            }
            else
            {
                saveFileDialog1.FileName = "";
                saveFileDialog1.Filter = "无损音乐格式(*.wav)|*.wav";
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    SpVoice spv = new SpVoice();
                    if (spv == null) return;
                    SpFileStream cpFileStream = new SpFileStream();
                    cpFileStream.Open(saveFileDialog1.FileName, SpeechStreamFileMode.SSFMCreateForWrite, false);
                    spv.AudioOutputStream = cpFileStream;
                    spv.Voice = spv.GetVoices(string.Empty, string.Empty).Item(cmbVoices.SelectedIndex);
                    spv.Volume = trVolume.Value;
                    spv.Speak(txtSpeach.Text, SpeechVoiceSpeakFlags.SVSFDefault);
                    cpFileStream.Close();

                    System.IO.FileInfo f = new System.IO.FileInfo(saveFileDialog1.FileName);

                    if (File.Exists(saveFileDialog1.FileName))
                    {
                        CustomMessageBox.CustomMessageBox.Show(f.Name + " 保存成功", "提示", CustomMessageBox.CustomMessageBox.MsgBoxButtons.OK, CustomMessageBox.CustomMessageBox.MsgBoxIcons.Info);
                    }
                    else
                    {
                        CustomMessageBox.CustomMessageBox.Show(f.Name + " 保存失败", "警告", CustomMessageBox.CustomMessageBox.MsgBoxButtons.OK, CustomMessageBox.CustomMessageBox.MsgBoxIcons.Error);
                    }
               }

            }
        }
示例#24
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            System.DateTime currentTime = new System.DateTime();

            currentTime = System.DateTime.Now;

            label3.Text = currentTime.ToString("HH:mm:ss");


            for (int i = 0; i < listView1.Items.Count; i++)
            {
                if (label3.Text == listView1.Items[i].SubItems[1].Text.ToString())
                {
                    for (int j = 0; j < Convert.ToInt32(textBox2.Text); j++)
                    {
                        SpeechVoiceSpeakFlags flag = SpeechVoiceSpeakFlags.SVSFlagsAsync;
                        SpVoice voice     = new SpVoice();
                        string  voice_txt = listView1.Items[i].SubItems[3].Text.ToString();
                        voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
                        voice.Speak(voice_txt, flag);
                    }
                }
            }
        }
示例#25
0
        public SapiTalk()
        {
            try
            {
                sapi = new SpVoice();
                SpObjectTokenCategory sapiCat = new SpObjectTokenCategory();
                Dictionary <string, SpObjectToken> TokerPool = new Dictionary <string, SpObjectToken>();

                // See https://qiita.com/7shi/items/7781516d6746e29c03b4
                sapiCat.SetId(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices", false);

                foreach (SpObjectToken token in sapiCat.EnumerateTokens())
                {
                    if (!TokerPool.ContainsKey(token.GetAttribute("name")))
                    {
                        TokerPool.Add(token.GetAttribute("name"), token);
                    }
                }

                foreach (SpObjectToken token in sapi.GetVoices("", ""))
                {
                    if (!TokerPool.ContainsKey(token.GetAttribute("name")))
                    {
                        TokerPool.Add(token.GetAttribute("name"), token);
                    }
                }

                SpeakerList = TokerPool.Select((val, idx) => new { Key = idx, Value = val.Value }).ToDictionary(s => s.Key, s => s.Value);

                ScanOutputDevices();
            }
            catch (Exception e)
            {
                Console.WriteLine("{0},{1},{2}", e.Message, e.InnerException == null ? "" : e.InnerException.Message, e.StackTrace);
            }
        }
示例#26
0
        private void start_Tick(object sender, EventArgs e)
        {
            if (xyzt.wlzt == true)
            {
                //Random shuiji = new Random();

                //WaveInfo wav = new WaveInfo(path);
                //xydo.alltime = (int)wav.Second * 1000;
                Random shuiji = new Random();



                SpVoice  voice = new SpVoice();//SAPI 5.4
                string[] word  = File.ReadAllLines(@".\\yuyinku\1.txt", System.Text.Encoding.Default);

                voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
                voice.Speak(word[shuiji.Next(0, word.Length)]);
                string path = @".\\bgm\111345.2.0.wav";
                System.Media.SoundPlayer player = new System.Media.SoundPlayer(path);
                player.Play();
            }
            System.Diagnostics.Process.Start(@".\\VoiceInput\VoiceInput.exe");
            this.start.Enabled = false;
        }
示例#27
0
        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盘防护扫描";
        }
示例#28
0
        private void MonitorSpeak()
        {
            SpVoice spv = new SpVoice();
            if (spv == null) return;

            spv.Voice = spv.GetVoices(string.Empty, string.Empty).Item(cmbVoices.SelectedIndex);
            spv.Volume = 100;

            spv.Speak(sendString, SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault);

            speak_Thread.Abort();
            speak_Thread.Join();
            speak_Thread = null;
        }
示例#29
0
        static void Main(string[] args)
        {
            SpVoice voice = new SpVoice();
            foreach( SpObjectToken sp in voice.GetVoices() )
            { Console.WriteLine(sp.GetDescription()); }

            Stack<Interest> Dialogue = new Stack<Interest>();
            Queue<Voice> talkers = new Queue<Voice>();

            talkers.Enqueue(new Voice { Name = "Bao Dur", _root = ChatNode.FromString(File.ReadAllText("lines/lines_Bao-Dur.txt")) });
            talkers.Enqueue(new Voice { Name = "Kreia", _root = ChatNode.FromString(File.ReadAllText("lines/lines_Kreia.txt")) });
            talkers.Enqueue(new Voice { Name = "Exile", _root = ChatNode.FromString(File.ReadAllText("lines/lines_Exile.txt")) });
            //talkers.Enqueue(new Voice { Name = "WHO", _root = ChatNode.FromString(File.ReadAllText("lines/lines_Who.txt")) });
            Voice[] ppl = talkers.ToArray();

            Random rand = new Random();

            /* Add a point of Interest.  These could be raised by finding items, doing quests, ect. */
            Dialogue.Push(new Interest { Tags = new string[1] { "Greeting" } });


            Module.GetString = (path) =>
            {
                var arpath = path.ToLower().Split('/');
                if (arpath[0] == "last")
                {
                    var ln = Dialogue.Peek() as Line;
                    if (ln != null)
                    {
                        return ln.Author.GetString(arpath[1]);
                    }
                }
                return "";
            };
            string[] current_topic = null;
            string response_name = null;
            Line response = null;
            while (
                //TODO -- Find the Person with the highest level of interest.
                talkers.Any(talker =>
                   talker.HasInterest(current_topic = Dialogue.Peek().Tags, TOLERANCE)
                   && !Dialogue.Contains(response = talker._root.VoiceInterest(current_topic))
                   && (response_name = talker.Name) != null /*OH MY GOD YOU LAZY GIT*/
                   && (response.Author = talker) != null
                )
            )
            {
                var strng = response.Output.Select(l => l.Resolve()).Aggregate((a, b) => a + b);
                Console.WriteLine(String.Format("{0}: {1}", response_name, strng) );
                voice.Speak(strng);
                Dialogue.Push(response);
                // Oh god, Stop me, please.
                // Just re-queues the talkers in random order
                // I really don't need a Queue anymore, I should just access an enumerable in a random fashion
                talkers.Enqueue(talkers.Dequeue());
                /*talkers.Clear();
                var numbs = Enumerable.Range(0, ppl.Length).ToList();
                while (numbs.Any())
                {
                    int i = rand.Next(numbs.Count());
                    int ind = numbs.ElementAt(i);
                    numbs.RemoveAt(i);
                    talkers.Enqueue(ppl[ind]);
                }*/
            }
            Console.ReadLine();
        }
示例#30
0
        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;
        }
示例#31
0
 public static void Speek(string word)
 {
     var voice = new SpVoice();
     voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
     voice.Speak(word);
 }
示例#32
0
        private void Speech(string message)
        {

#if SPEECH_API      //  using System.Speech.Synthesis;
            SpeechSynthesizer synth = new SpeechSynthesizer();
            synth.SpeakAsync("您有新的提交方案需签字");
#endif

#if SPEECH_COM      //  using SpeechLib

            //这些方法和对象到底是什么意思,可以自己去百度或者google一下,我也不是很清楚
            SpeechVoiceSpeakFlags ss = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            SpVoice sp = new SpVoice();
            sp.Voice = sp.GetVoices(String.Empty, String.Empty).Item(0);
            sp.Speak("您有新的提交方案需签字", ss);//textBox1就是一个文本框,点击button1的时候系统读取该文本框的文字
#endif
        }
示例#33
0
        private void start_Speak()
        {
            SpVoice spv = new SpVoice();
            if (spv == null) return;

            spv.Voice = spv.GetVoices(string.Empty, string.Empty).Item(cmbVoices.SelectedIndex);
            spv.Volume = 100;

            spv.Speak("警告!!检测到可自执行文件,建议使用U盘防护扫描", SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault);
        }
示例#34
0
        public SpeechService(ServiceCreationInfo info)
            : base("speech", info)
        {
            mVoice = new SpVoice();

            // Select voice
            string voiceName = null;
            try
            {
                voiceName = info.Configuration.Voice;
            }
            catch (RuntimeBinderException) {}

            if (!string.IsNullOrEmpty(voiceName))
            {
                SpObjectToken voiceToken = null;

                CultureInfo culture = new CultureInfo("en-US");
                foreach (var voice in mVoice.GetVoices())
                {
                    var token = voice as SpObjectToken;
                    if (token == null)
                        continue;

                    if (culture.CompareInfo.IndexOf(token.Id, voiceName, CompareOptions.IgnoreCase) < 0)
                        continue;

                    voiceToken = token;
                }

                if (voiceToken != null)
                    mVoice.Voice = voiceToken;
            }

            // Select output. Why isn't this default any longer?
            var enumerator = new MMDeviceEnumerator();
            MMDevice endpoint = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);
            if (endpoint != null)
            {
                foreach (var output in mVoice.GetAudioOutputs())
                {
                    var token = output as SpObjectToken;
                    if (token == null)
                        continue;

                    if (token.Id.IndexOf(endpoint.ID) < 0)
                        continue;

                    mVoice.AudioOutput = token;
                    break;
                }
            }

            mVoiceCommands = new Dictionary<string, DeviceBase.VoiceCommand>();

            mInput = new AudioInput();

            mRecognizer = new SpeechRecognitionEngine();
            mRecognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(OnSpeechRecognized);
            mRecognizer.RecognizerUpdateReached += new EventHandler<RecognizerUpdateReachedEventArgs>(OnUpdateRecognizer);
            mRecognizer.RecognizeCompleted += new EventHandler<RecognizeCompletedEventArgs>(OnRecognizeCompleted);

            var grammar = new Grammar(new GrammarBuilder(new Choices(new string[] { "computer" })));
            mRecognizer.LoadGrammar(grammar);

            var speechFormat = new SpeechAudioFormatInfo(44100, AudioBitsPerSample.Sixteen, AudioChannel.Mono);
            mRecognizer.SetInputToAudioStream(mInput.mStream, speechFormat);

            mRecognizer.RecognizeAsync(RecognizeMode.Multiple);
        }
示例#35
0
        private void start_Speak()
        {
            SpVoice spv = new SpVoice();
            if (spv == null) return;

            spv.Voice = spv.GetVoices(string.Empty, string.Empty).Item(cmbVoices.SelectedIndex);
            spv.Volume = trVolume.Value;

            spv.Speak(txtSpeach.Text, SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault);

            if (closeFlag == 0)
            {
                CustomMessageBox.CustomMessageBox.Show("文本阅读完毕", "提示", CustomMessageBox.CustomMessageBox.MsgBoxButtons.OK, CustomMessageBox.CustomMessageBox.MsgBoxIcons.Info);
            }

            if (speak_Thread.IsAlive)
            {
                speak_Thread.Abort();
                speak_Thread.Join();
                speak_Thread = null;
            }
        }
示例#36
0
 private void button1_Click(object sender, EventArgs e)
 {
     SpVoice voice = new SpVoice();//SAPI 5.4,我的是win7系统自带的Microsoft Speech  object  library是5.4版本
     voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
     voice.Speak( richTextBox1.Text.Trim(), SpeechVoiceSpeakFlags.SVSFlagsAsync);//默认是女声说话
 }
 private void init_vox()
 {
     vox = new SpVoice();
     var voices = vox.GetVoices();
     voiceNames = new string[voices.Count];
     for (int i = 0; i < voices.Count; i++) {
         var voice = voices.Item(i);
         var name = voice.GetDescription();
         voiceNames[i] = name;
     }
 }