i’ve been experimenting with the TTS functionality of Google Translate which you can access via HTTP in a browser. I have read it uses WAV as audiotype. My code compiles but nothing plays; I can see in the Inspector that the AudioSource Audio Clip is set when the script runs, but when I bring up the Select Audio Clip, it says “Can not show PCM data for this file” and there are 0 bits etc.
Am I missing something here? Would be great to get this working as it would provide many languages for TTS
This is my code, which runs in an Init() function when the app starts.
var www : WWW = new WWW ("http://translate.google.com/translate_tts?tl=en&q=hello");
yield www;
VoiceAudio.clip = www.GetAudioClip(false, true, AudioType.WAV);
VoiceAudio.Play();
using UnityEngine;
using System.Collections;
using System.Text.RegularExpressions;
/// <summary>
/// <author>Jefferson Reis</author>
/// <explanation>Works only on Android. To test, change the platform to Android.</explanation>
/// </summary>
public class GoogleTextToSpeech : MonoBehaviour
{
public string words = "Hello";
IEnumerator Start ()
{
// 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://translate.google.com/translate_tts?tl=en&q=" + result;
WWW www = new WWW (url);
yield return www;
audio.clip = www.GetAudioClip (false, false, AudioType.MPEG);
audio.Play ();
}
void OnGUI ()
{
words = GUI.TextField (new Rect (Screen.width / 2 - 200 / 2, 10, 200, 30), words);
if (GUI.Button (new Rect (Screen.width / 2 - 150 / 2, 40, 150, 50), "Speak")) {
StartCoroutine (Start ());
}
}
}//closes the class
@JeffersonReis@terraformer@fuyangli
Have you run this code on your android phone… bcz i tried the same code on the phone but it is not working. Can you help me on these ??