Пример #1
0
        /// <summary>
        /// Returns all available voices.
        /// </summary>
        /// <returns>List of voice informations</returns>
        public List <Voice> GetVoices()
        {
            List <Voice> voices = new List <Voice>();

            if (InstalledVoices != null && InstalledVoices.Count > 0)
            {
                voices.AddRange(InstalledVoices);
            }
            else if (Speaker != null)
            {
                var iv = Speaker.GetInstalledVoices();
                foreach (var v in iv)
                {
                    InstalledVoice voice = v as InstalledVoice;
                    if (voice != null)
                    {
                        VoiceInfo vi = voice.VoiceInfo;
                        voices.Add(new Voice(
                                       vi.Name,
                                       vi.Culture.Name,
                                       vi.Gender.ToString(),
                                       vi.Age.ToString()
                                       ));
                    }
                }
                InstalledVoices = voices;
            }
            return(voices);
        }
Пример #2
0
            public ThreadedSpeak(string Word)
            {
                this.Word = Word;
                CultureInfo    keyboardLanguage = System.Windows.Forms.InputLanguage.CurrentInputLanguage.Culture;
                InstalledVoice neededVoice      = this.SpeechSynth.GetInstalledVoices(keyboardLanguage).FirstOrDefault();

                if (neededVoice == null)
                {
                    //http://superuser.com/questions/590779/how-to-install-more-voices-to-windows-speech
                    //https://msdn.microsoft.com/en-us/library/windows.media.speechsynthesis.speechsynthesizer.voice.aspx
                    //http://stackoverflow.com/questions/34776593/speechsynthesizer-selectvoice-fails-with-no-matching-voice-is-installed-or-th
                    this.Word = "Unsupported Language";
                }
                else if (!neededVoice.Enabled)
                {
                    this.Word = "Voice Disabled";
                }
                else
                {
                    try
                    {
                        this.SpeechSynth.SelectVoice(neededVoice.VoiceInfo.Name);
                    }
                    catch (Exception ex)
                    {
                        Debug.Assert(false, ex.ToString());
                    }
                }

                SpeechSynth.Rate   = -1;
                SpeechSynth.Volume = 100;
            }
Пример #3
0
 private void SetSynthVoice(InstalledVoice currentVoice)
 {
     if (currentVoice != null)
     {
         synth.SelectVoice(CurrentVoice.VoiceInfo.Name);
     }
 }
Пример #4
0
        /// <summary>
        /// Try to find a suitable english TTS voice to use
        /// </summary>
        /// <returns>The name of the default voice to use</returns>
        private string GetDefaultVoice()
        {
            // First try to find a male English voice
            InstalledVoice voice =
                (from InstalledVoice v in Reader.GetInstalledVoices() where v.Enabled &&
                 v.VoiceInfo.Culture.TwoLetterISOLanguageName.ToLowerInvariant() == "en" &&
                 v.VoiceInfo.Gender == VoiceGender.Male select v).SingleOrDefault();

            if (voice != null)
            {
                return(voice.VoiceInfo.Name);
            }

            // If no male voice found, pick any English voice
            voice =
                (from InstalledVoice v in Reader.GetInstalledVoices()
                 where v.Enabled &&
                 v.VoiceInfo.Culture.TwoLetterISOLanguageName.ToLowerInvariant() == "en"
                 select v).SingleOrDefault();
            if (voice != null)
            {
                return(voice.VoiceInfo.Name);
            }

            return(null); // No voice found, return null
        }
Пример #5
0
 public void SelectVoice(string voiceName)
 {
     if (this.AvailableVoices.Contains(voiceName))
     {
         this.speechSynthesizer.SelectVoice(voiceName);
         return;
     }
     foreach (InstalledVoice current in this.speechSynthesizer.GetInstalledVoices())
     {
         string value = VirtualAssistant.Instance.SettingsManager["Speech"]["Gender"].Value;
         if (current.VoiceInfo.Gender.ToString().Equals(value, StringComparison.OrdinalIgnoreCase))
         {
             this.speechSynthesizer.SelectVoice(current.VoiceInfo.Name);
             return;
         }
     }
     using (IEnumerator <InstalledVoice> enumerator = this.speechSynthesizer.GetInstalledVoices().GetEnumerator())
     {
         if (enumerator.MoveNext())
         {
             InstalledVoice current2 = enumerator.Current;
             this.speechSynthesizer.SelectVoice(current2.VoiceInfo.Name);
         }
     }
 }
Пример #6
0
 public SpeechString(string text, InstalledVoice voice, int rate, int volume, SoundDevice device1, SoundDevice device2)
 {
     Text            = text;
     Voice           = voice;
     Rate            = rate;
     Volume          = volume;
     PrimaryDevice   = device1;
     SecondaryDevice = device2;
 }
Пример #7
0
 /// <summary>
 /// Queues a TTS task if the queue isn't full.
 /// </summary>
 /// <param name="text">Text to speak.</param>
 /// <param name="device1">The <see cref="SoundDevice"/> to use when speaking.</param>
 /// <param name="voice">The voice to use.</param>
 /// <param name="rate">The rate to speak this text at. Clamped to [<see cref="MIN_RATE"/>, <see cref="MAX_RATE"/>].</param>
 /// <param name="volume">The volume to speak this text at. Clamped to [<see cref="MIN_VOLUME"/>, <see cref="MAX_VOLUME"/>].</param>
 public void QueueTTS(string text, SoundDevice device1, SoundDevice device2, InstalledVoice voice, int rate = DEFAULT_RATE, int volume = DEFAULT_VOLUME)
 {
     if (!IsQueueFull())
     {
         SpeechString data = new SpeechString(text, voice, rate, volume, device1, device2);
         TTSQueue.Enqueue(data);
         TTSHistory.Enqueue(data);
     }
 }
Пример #8
0
        public static void InitiateSynth()
        {
            IReadOnlyCollection <InstalledVoice> InstalledVoices = speechSynthesizer.GetInstalledVoices();
            InstalledVoice InstalledVoice = InstalledVoices.First();

            speechSynthesizer.SelectVoice(InstalledVoice.VoiceInfo.Name);
            Console.Write(InstalledVoice.VoiceInfo.Name);
            speechSynthesizer.Rate = 1;
            speechSynthesizer.SpeakAsync(Processor.Greeting());
        }
Пример #9
0
        public bool SelectVoice(InstalledVoice voice)
        {
            var voiceInformation = SpeechSynthesizer.AllVoices.FirstOrDefault(v => v.Id == voice.Id);

            if (voiceInformation != null)
            {
                synthesizer.Voice = voiceInformation;
                return(true);
            }

            return(false);
        }
Пример #10
0
        public void Init()
        {
            speechSynthesizer = new SpeechSynthesizer();
            speechSynthesizer.SetOutputToDefaultAudioDevice();
            speechSynthesizer.Volume = DEFAULT_VOLUME;

            InstalledVoice voice = speechSynthesizer.GetInstalledVoices(Culture).FirstOrDefault();

            if (voice != null)
            {
                speechSynthesizer.SelectVoice(voice.VoiceInfo.Name);
            }
        }
Пример #11
0
        public void SetTTSVoices()
        {
            SpeechSynthesizer speaker = new SpeechSynthesizer();

            _TextToSpeachVoices = speaker.GetInstalledVoices(new CultureInfo("ru-RU"));
            if (_TextToSpeachVoices.Count == 0)
            {
                System.Windows.MessageBox.Show("В Windows не установлены голоса для синтеза речи на русском языке. Установите пожалуйста, а то ничего не будет слышно. Гуглить по запросам TTS SAPI 5, MS Speach Platform ");
                _TTSVoice = null;
                return;
            }
            _TTSVoice = _TextToSpeachVoices[0];
        }
Пример #12
0
        /// <summary>
        /// SAPIな発声エンジンを設定するメソッド。
        /// </summary>
        /// <param name="voice">readonlyなメンバーinstalledVoiceの中のうちの1つ。</param>
        public bool SetSpeakingSAPIMethod(InstalledVoice voice)
        {
            try
            {
                synthesizer.SelectVoice(voice.VoiceInfo.Name);

                SpeakingType = SynthesizerType.SAPI;
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Пример #13
0
        private void AddInstalledVoicesToList()
        {
            IReadOnlyCollection <InstalledVoice> installedVoices = synthesizer.GetInstalledVoices();

            for (int i = 0; i < installedVoices.Count; i++)
            {
                InstalledVoice voice = installedVoices.ElementAt(i);
                if (voice.Enabled)
                {
                    DDLAvailableVoices.Items.Add(installedVoices.ElementAt(i).VoiceInfo.Name);
                }
            }
            DDLAvailableVoices.SelectedIndex = 0;
        }
Пример #14
0
        public static async void TestVoice(InstalledVoice voice)
        {
            voice.Enabled = true;

            await Task.Run(() => {
                using (SpeechSynthesizer synthesizer = new SpeechSynthesizer())
                {
                    // show installed voices
                    synthesizer.Rate   = Rate;
                    synthesizer.Volume = Volume;
                    synthesizer.SelectVoice(voice.VoiceInfo.Name);
                    synthesizer.SetOutputToDefaultAudioDevice();
                    synthesizer.Speak($"Hello, my name is {voice.VoiceInfo.Name}.");
                }
            });
        }
Пример #15
0
        private static string FindFullVoiceName(string voiceArgument)
        {
            string voiceName = null;

            using (SpeechSynthesizer synthesizer = new SpeechSynthesizer())
            {
                System.Collections.ObjectModel.ReadOnlyCollection <InstalledVoice> installedVoices = synthesizer.GetInstalledVoices();
                System.Collections.Generic.IEnumerable <InstalledVoice>            enabledVoices   = installedVoices.Where(voice => voice.Enabled);

                InstalledVoice selectedVoice = enabledVoices.FirstOrDefault(voice => voice.VoiceInfo.Name.ToLowerInvariant().Contains(voiceArgument));
                if (selectedVoice != null)
                {
                    voiceName = selectedVoice.VoiceInfo.Name;
                }
            }
            return(voiceName);
        }
Пример #16
0
        //public static List<string> voices;
        public static void TextToSpeech()
        {
            _ss.Volume = 100;
            _ss.Rate   = 1;
            int i = 1;

            Console.WriteLine("Installed TTS voices\r\n");



            foreach (object obj in _ss.GetInstalledVoices())
            {
                InstalledVoice voice = (InstalledVoice)obj;
                Console.WriteLine(i + ".)\t" + voice.VoiceInfo.Name);
                //voices.Add(voice.VoiceInfo.Name);
                i++;
            }
            //int voicenumber = input();
            //_ss.SelectVoice(voices[voicenumber]);
            Console.ReadKey();
        }
Пример #17
0
        //public void SayC
        //string text = textBox1.Text;

        //if (text.Trim().Length != 0)
        //{
        // speech.Rate = 5;//语速
        // speech.SelectVoice("Microsoft Lili");//设置播音员(中文)
        // //speech.SelectVoice("Microsoft Anna"); //英文
        // speech.Volume = 100; //音量
        // speech.SpeakAsync(textBox1.Text);//语音阅读方法
        //} 
        #endregion

        #region 可以读取中文
        public static void SayChinese(string phrase)
        {
            SpeechSynthesizer speech = new SpeechSynthesizer();

            speech.Rate   = 2;   //语速
            speech.Volume = 100; //音量
            CultureInfo    keyboardCulture = System.Windows.Forms.InputLanguage.CurrentInputLanguage.Culture;
            InstalledVoice neededVoice     = speech.GetInstalledVoices(keyboardCulture).FirstOrDefault();

            if (neededVoice == null)
            {
                phrase = "Unsupported Language";
            }
            else if (!neededVoice.Enabled)
            {
                phrase = "Voice Disabled";
            }
            else
            {
                speech.SelectVoice(neededVoice.VoiceInfo.Name);
            }
            speech.Speak(phrase);
        }
Пример #18
0
 internal WinAvailableVoice(InstalledVoice i)
 {
     winVoice = i;
     Name = i.VoiceInfo.Name;
     Male = (winVoice.VoiceInfo.Gender == VoiceGender.Male);
 }
Пример #19
0
 private void selectEnglishEngine_click(Object sender, EventArgs e)
 {
     _enVoice = (InstalledVoice)(((ToolStripMenuItem)sender).Tag);
 }
Пример #20
0
 private void VoiceDropdown_ContextMenuClosing(object sender, ContextMenuEventArgs e)
 {
     selectedVoice = installedVoices[VoiceDropdown.SelectedIndex];
 }
Пример #21
0
 private void selectJapaneseEngine_click(Object sender, EventArgs e)
 {
     _jpVoice = (InstalledVoice)(((ToolStripMenuItem)sender).Tag);
 }
Пример #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InstalledVoiceImplementation" /> class.
 /// </summary>
 /// <param name="installedVoice">The installed voice.</param>
 public InstalledVoiceImplementation(InstalledVoice installedVoice)
 {
     this.installedVoice = installedVoice;
 }
Пример #23
0
        private void EngineMenuItem_DropDownOpeningCommon(string lng, ToolStripMenuItem parent, EventHandler eh, InstalledVoice curV)
        {
            if (!initSpeechEngine())
            {
                return;
            }

            parent.DropDownItems.Clear();

            foreach (InstalledVoice iv in _syn.GetInstalledVoices())
            {
                if (iv.Enabled)
                {
                    string dn = iv.VoiceInfo.Culture.Name.ToLower();
                    if (dn.StartsWith(lng.ToLower()))
                    {
                        ToolStripMenuItem mi = new ToolStripMenuItem();
                        mi.Text   = iv.VoiceInfo.Description;
                        mi.Tag    = iv;
                        mi.Click += eh;
                        if (curV != null && curV.VoiceInfo.Id == iv.VoiceInfo.Id)
                        {
                            mi.Checked = true;
                        }
                        parent.DropDownItems.Add(mi);
                    }
                }
            }

            if (parent.DropDownItems.Count == 0)
            {
                ToolStripMenuItem miNone = new ToolStripMenuItem();
                miNone.Text    = "<NONE>";
                miNone.Enabled = false;
                parent.DropDownItems.Add(miNone);
            }
        }
Пример #24
0
 public VoiceVM(InstalledVoice voice)
 {
     Id   = voice.VoiceInfo.Id.ToLower();
     Name = $"{voice.VoiceInfo.Name} {voice.VoiceInfo.Culture.DisplayName}";
 }
Пример #25
0
 public VoiceInList(InstalledVoice installedVoice)
 {
     InstalledVoice = installedVoice;
 }
Пример #26
0
 internal WinAvailableVoice(InstalledVoice i)
 {
     winVoice = i;
     Name     = i.VoiceInfo.Name;
     Male     = (winVoice.VoiceInfo.Gender == VoiceGender.Male);
 }
Пример #27
0
        private void LogIn_Load(object sender, EventArgs e)
        {
            string message = "Welcome!! Please Enter your Login Credentials";

            speechReader.Dispose();
            speechReader = new SpeechSynthesizer();
            IReadOnlyCollection <InstalledVoice> installedVoices = speechReader.GetInstalledVoices();
            InstalledVoice voice = installedVoices.First();

            speechReader.SelectVoice(voice.VoiceInfo.Name);
            speechReader.SpeakAsync(message);


            //Check if the Custom font Exits Then Use if it does exist
            if (File.Exists(@"Fonts\BOD_R.ttf"))
            {
                PrivateFontCollection pfc = new PrivateFontCollection();
                pfc.AddFontFile(@"Fonts\Blackletter686 BT.ttf");

                foreach (Control control in Controls)
                {
                    if (control is GroupBox)
                    {
                        (control).Font = new System.Drawing.Font(pfc.Families[0], 22.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    }
                }
            }
            //DataBase Access and Operations
            if (DBConnection.State.Equals(ConnectionState.Closed))
            {
                DBConnection.Open();
            }

            try
            {
                if (DBConnection.State.Equals(ConnectionState.Closed))
                {
                    DBConnection.Open();
                }
                sqlite_cmd             = DBConnection.CreateCommand();
                sqlite_cmd.CommandType = CommandType.Text;

                //Check if  First Table exists
                sqlite_cmd.CommandText = "SELECT name FROM sqlite_master WHERE name= 'AuthorizedUsers'";
                var name = sqlite_cmd.ExecuteScalar();
                //check if table exists
                if (name != null && name.ToString() == "AuthorizedUsers")
                {
                    return;
                }
                else
                {
                    //If not Exist then Create First Table
                    sqlite_cmd.CommandText = "CREATE TABLE AuthorizedUsers( id  INTEGER,UserName VARCHAR(45) PRIMARY KEY,Password VARCHAR(45));";
                    sqlite_cmd.ExecuteNonQuery();
                    //insert Defaults into First Table
                    sqlite_cmd.CommandText = "INSERT INTO AuthorizedUsers(id,UserName,Password) VALUES(1,'admin','1234');";
                    sqlite_cmd.ExecuteNonQuery();
                }

                //Check if  Second Table exists
                sqlite_cmd.CommandText = "SELECT name FROM sqlite_master WHERE name= 'AvailableSubjects'";
                var name2 = sqlite_cmd.ExecuteScalar();
                //check if table exists
                if (name2 != null && name.ToString() == "AvailableSubjects")
                {
                    return;
                }
                else
                {
                    //If not Exist then Create Second Table
                    sqlite_cmd.CommandText = "CREATE TABLE AvailableSubjects (id INTEGER PRIMARY KEY, Subjects VARCHAR(45), Teacher  VARCHAR(45));";
                    sqlite_cmd.ExecuteNonQuery();
                }

                //Check if  Third Table exists
                sqlite_cmd.CommandText = "SELECT name FROM sqlite_master WHERE name= 'Classes'";
                name = sqlite_cmd.ExecuteScalar();
                //check if table exists
                if (name != null && name.ToString() == "Classes")
                {
                    return;
                }
                else
                {
                    //If not Exist
                    //Create Third Table
                    sqlite_cmd.CommandText = "CREATE TABLE Classes (id INTEGER PRIMARY KEY,Class VARCHAR(45));";
                    sqlite_cmd.ExecuteNonQuery();

                    //insert Defaults into Third Table
                    sqlite_cmd.CommandText = "INSERT INTO Classes(id,Class)  VALUES(1,'Jss1')";
                    sqlite_cmd.ExecuteNonQuery();
                    sqlite_cmd.CommandText = "INSERT INTO Classes(id,Class)  VALUES(2,'Jss2')";
                    sqlite_cmd.ExecuteNonQuery();
                    sqlite_cmd.CommandText = "INSERT INTO Classes(id,Class)  VALUES(3,'Jss3')";
                    sqlite_cmd.ExecuteNonQuery();
                }

                //Check if  Fourth Table exists
                sqlite_cmd.CommandText = "SELECT name FROM sqlite_master WHERE name= 'StudentRecord'";
                name = sqlite_cmd.ExecuteScalar();
                //check if table exists
                if (name != null && name.ToString() == "StudentRecord")
                {
                    return;
                }
                else
                {
                    //If not Exist then Create First Table
                    //Create Fourth Table
                    sqlite_cmd.CommandText = @"CREATE TABLE StudentRecord (StudentID  STRING,FirstName VARCHAR(100),LastName VARCHAR(100),FullName  VARCHAR(100) PRIMARY KEY, DOB VARCHAR,
    State            VARCHAR(100),
    Sex              VARCHAR(10),
    Class            VARCHAR(10),
    English          INTEGER NOT NULL DEFAULT (0),
    Maths            INTEGER NOT NULL DEFAULT (0),
    BasicSci         INTEGER NOT NULL DEFAULT (0),
    BusStd           INTEGER NOT NULL DEFAULT (0),
    SocialStd        INTEGER NOT NULL DEFAULT (0),
    BasicTech        INTEGER NOT NULL DEFAULT (0),
    Total            INTEGER NOT NULL DEFAULT (0),
    Average          DOUBLE (20) NOT NULL DEFAULT (0),
    Address          VARCHAR (200),
    Image            BLOB,
    ParentPhone      VARCHAR (20),
    PrincipalComment VARCHAR,
    TeacherComment   VARCHAR
);";
                    sqlite_cmd.ExecuteNonQuery();
                }


                //Check if  Fifth Table exists
                sqlite_cmd.CommandText = "SELECT name FROM sqlite_master WHERE name= 'SessionDetails'";
                name = sqlite_cmd.ExecuteScalar();
                //check if table exists
                if (name != null && name.ToString() == "SessionDetails")
                {
                    return;
                }
                else
                {
                    //If not Exist then Create Fifth Table
                    sqlite_cmd.CommandText = "CREATE TABLE SessionDetails( id  INTEGER PRIMARY KEY,Term VARCHAR(45),Session VARCHAR(45),SchoolName VARCHAR(45), Address VARCHAR(45));";
                    sqlite_cmd.ExecuteNonQuery();
                    //insert Defaults into Fifth Table
                    sqlite_cmd.CommandText = @"INSERT INTO SessionDetails(Term,Session, SchoolName, Address) VALUES('1st', '2015/2016','YETKEM HIGH SCHOOL','Yetkem Avenue, Surulere, Alagbado, Lagos State.');";
                    sqlite_cmd.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        } //End LogIn_Load