Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Text.RegularExpressions;
- /*
- * Internet required to operate.
- *
- * Heads up! ISpeech is NOT free, but you can use as a developer. More information here:
- * https://www.ispeech.org/developer/purchase/plans
- *
- * Documentation: http://www.ispeech.org/api
- *
- */
- public class ISpeechTTS : MonoBehaviour {
- public string words = "Hello";
- //============== TTS settings ==============
- public enum VOICES {
- //US English Female (default)
- usenglishfemale,
- //US English Male
- usenglishmale,
- //UK English Female
- ukenglishfemale,
- //UK English Male
- ukenglishmale,
- //Australian English Female
- auenglishfemale,
- //US Spanish Female
- usspanishfemale,
- //US Spanish Male
- usspanishmale,
- //Chinese Female
- chchinesefemale,
- //Chinese Male
- chchinesemale,
- //Hong Kong Cantonese Female
- hkchinesefemale,
- //Taiwan Chinese Female
- twchinesefemale,
- //Japanese Female
- jpjapanesefemale,
- //Japanese Male
- jpjapanesemale,
- //Korean Female
- krkoreanfemale,
- //Korean Male
- krkoreanmale,
- //Canadian English Female
- caenglishfemale,
- //Hungarian Female
- huhungarianfemale,
- //Brazilian Portuguese Female
- brportuguesefemale,
- //European Portuguese Female
- eurportuguesefemale,
- //European Portuguese Male
- eurportuguesemale,
- //European Spanish Female
- eurspanishfemale,
- //European Spanish Male
- eurspanishmale,
- //European Catalan Female
- eurcatalanfemale,
- //European Czech Female
- eurczechfemale,
- //European Danish Female
- eurdanishfemale,
- //European Finnish Female
- eurfinnishfemale,
- //European French Female
- eurfrenchfemale,
- //European French Male
- eurfrenchmale,
- //European Norwegian Female
- eurnorwegianfemale,
- //European Dutch Female
- eurdutchfemale,
- //European Polish Female
- eurpolishfemale,
- //European Italian Female
- euritalianfemale,
- //European Italian Male
- euritalianmale,
- //European Turkish Female
- eurturkishfemale,
- //European Turkish Male
- eurturkishmale,
- //European German Female
- eurgermanfemale,
- //European German Male
- eurgermanmale,
- //Russian Female
- rurussianfemale,
- //Russian Male
- rurussianmale,
- //Swedish Female
- swswedishfemale,
- //Canadian French Female
- cafrenchfemale,
- //Canadian French Male
- cafrenchmale
- };
- public VOICES voiceStyle;
- //-----------------------------
- private AudioType audioType;
- public enum AUDIOFORMAT{
- mp3,
- ogg,
- mp4,
- wav,
- wma
- }
- private AUDIOFORMAT audioFormat;
- //--------------------------------
- //put YOUR key to iSpeech here.
- public string ApiKey = "developerdemokeydeveloperdemokey";//developerdemokeydeveloperdemokey
- //==============================================
- public AudioSource audio = null;
- private WWW www;
- void Start ()
- {
- if(audio == null)
- {
- audio = GetComponent<AudioSource>();
- }
- #if UNITY_ANDROID
- audioFormat = AUDIOFORMAT.mp3;
- audioType = AudioType.MPEG;
- #else//Windows
- audioFormat = AUDIOFORMAT.ogg;
- audioType = AudioType.OGGVORBIS;
- #endif
- }
- IEnumerator GetTTS ()
- {
- // Remove the "spaces" in excess
- Regex rgx = new Regex ("\\s+");
- // Replace the "spaces" with "% 20" for the link Can be interpreted
- string result = rgx.Replace (words, "%20");
- string url = "http://api.ispeech.org/api/rest?"+"apikey="+ApiKey+"&action=convert"+"&voice="+voiceStyle+"&format="+audioFormat+"&frequency=44100"+"&text="+result;
- www = new WWW (url);
- yield return www;
- audio.clip = www.GetAudioClip (false,false,audioType);
- audio.Play ();
- }
- void OnGUI ()
- {
- words = GUI.TextField (new Rect (0, 10, Screen.width, 50), words);
- if (GUI.Button (new Rect (0, Screen.height-50-10, Screen.width, 50), "Speak")) {
- StartCoroutine (GetTTS ());
- }
- }
- }//fecha classe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement