Пример #1
0
    void OnGUI()
    {
        SpObjectTokenCategory tokenCat = new SpObjectTokenCategory();

        tokenCat.SetId(SpeechLib.SpeechStringConstants.SpeechCategoryVoices, false);
        ISpeechObjectTokens tokens = tokenCat.EnumerateTokens(null, null);
    }
Пример #2
0
    // 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 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;
    }
        /// <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");
        }
Пример #5
0
        public void initialize_audio()
        {
            SpObjectTokenCategory category = new SpObjectTokenCategory();

            category.SetId(SpeechStringConstants.SpeechCategoryAudioIn, false);

            SpObjectToken token = new SpObjectToken();

            token.SetId(category.EnumerateTokens().Item(0).Id, "", false);
            //token.SetId(category.Default, "", false);
            context.Recognizer.AudioInput = token;
        }
///




	//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.

	}
Пример #7
0
    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();
        }
    }
Пример #8
0
    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;
    }
Пример #9
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);
            }
        }
Пример #10
0
        static void Main(string[] args)
        {
            try
            {
                SpVoice sapi = new SpVoice();
                SpObjectTokenCategory sapiCat = new SpObjectTokenCategory();
                Dictionary <string, SpObjectToken> TokerPool = new Dictionary <string, SpObjectToken>();
                SpFileStream Sfs = null;

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

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

                // SAPI voices
                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);

                if (!Opt(args))
                {
                    return;
                }

                if (file != "")
                {
                    Sfs = new SpFileStream();
                    Sfs.Open(file, SpeechStreamFileMode.SSFMCreateForWrite);
                    sapi.AudioOutputStream = Sfs;
                }

                Thread t = new Thread(() => {
                    SpObjectToken backupSapi = sapi.Voice;
                    sapi.Voice  = SpeakerList[AvatorIdx];
                    sapi.Rate   = Speed;
                    sapi.Volume = Volume;
                    sapi.Speak(text);
                    sapi.Voice = backupSapi;
                });
                t.SetApartmentState(ApartmentState.STA);
                t.Start();
                t.Join();

                if (file != "")
                {
                    Sfs.Close();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("err:{0},{1}", e.Message, e.InnerException == null ? "" : e.InnerException.Message);
            }
        }
Пример #11
0
        //button5生成读音
        private void button5_Click(object sender, RoutedEventArgs e)
        {
            //数据库全部读出
            WordLogic[] wordList = WordLogic.FindAll();

            SpFileStream          SpFileStream = new SpFileStream();
            String                fileName;
            SpeechVoiceSpeakFlags SpFlags    = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            SpeechStreamFileMode  SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite;
            SpVoice               voice      = new SpVoice();

            // prepare voice
            SpObjectTokenCategory aotc = new SpObjectTokenCategory();

            aotc.SetId(SpeechLib.SpeechStringConstants.SpeechCategoryVoices);

            foreach (ISpeechObjectToken token in aotc.EnumerateTokens())
            {
                if (token.GetDescription() == "VW Julie")
                {
                    englishToken = (SpObjectToken)token;
                }
                else if (token.GetDescription() == "VW Hui")
                {
                    chineseToken = (SpObjectToken)token;
                }
            }

            voice.Voice = englishToken;
            voice.Rate  = -4;

            String outFolderPath = Directory.GetParent("../../TestCases/") + @"\单词音频\";

            if (!Directory.Exists(outFolderPath))
            {
                Directory.CreateDirectory(outFolderPath);
            }

            for (int i = 0; i < wordList.Length; i++)
            {
                String word = wordList[i].word;

                if (word != null)
                {
                    word = word.Trim();
                }

                if (String.IsNullOrEmpty(word))
                {
                    // 遇到无效内容,退出
                    continue;
                }
                word = convert(word);

                fileName = outFolderPath + word + ".wav";
                SpFileStream.Open(fileName, SpFileMode, false);
                voice.AudioOutputStream = SpFileStream;
                voice.Speak(word, SpFlags);
                voice.WaitUntilDone(Timeout.Infinite);
                SpFileStream.Close();
            }


            MessageBox.Show("音频生成完毕!");
        }