티스토리 뷰

분류없음

음성 테스트

Blog.Big.So 블로그빅소 2019.06.29 17:59
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Text.RegularExpressions;
  4.  
  5.  
  6. /// <summary>
  7. /// <author>Jefferson Reis</author>
  8. /// <explanation>Works only on Android, or platform that supports mp3 files. To test, change the platform to Android.</explanation>
  9. /// </summary>
  10.  
  11. public class GoogleTextToSpeech : MonoBehaviour
  12. {
  13. public string words = "Hello";
  14.  
  15. IEnumerator Start ()
  16. {
  17. // Remove the "spaces" in excess
  18. Regex rgx = new Regex ("\\s+");
  19. // Replace the "spaces" with "% 20" for the link Can be interpreted
  20. string result = rgx.Replace (words, "%20");
  21. string url = "http://translate.google.com/translate_tts?tl=en&q=" + result;
  22. WWW www = new WWW (url);
  23. yield return www;
  24. audio.clip = www.GetAudioClip (false, false, AudioType.MPEG);
  25. audio.Play ();
  26. }
  27.  
  28. void OnGUI ()
  29. {
  30. words = GUI.TextField (new Rect (Screen.width / 2 - 200 / 2, 10, 200, 30), words);
  31. if (GUI.Button (new Rect (Screen.width / 2 - 150 / 2, 40, 150, 50), "Speak")) {
  32. StartCoroutine (Start ());
  33. }
  34. }
  35.  
  36.  
  37. }//closes the class
댓글
댓글쓰기 폼