Google text-to-speech via HTTP

Hi,

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

It uses MP3 format, not WAV.

Thanks Adam,

Just curious, have you tried this yourself? Anyone else?

I tried (with streaming)

VoiceClip = www.GetAudioClip(false, true, AudioType.MPEG);

and (without streaming)

VoiceClip = www.GetAudioClip(false, false, AudioType.MPEG);

but both gives this error:
Streaming of ‘’ on this platform is not supported

I also tried to build it as a webplayer, if the ‘platform’ refers to the runtime environment?

I finally tried to upload the webplayer to a webserver but same thing there.

I develop on MacOSX with Unity 3.5.5

Best regards,
T.

Have you guys found how to make it work?

@terraformer @fuyangli

what platform were you trying to build for?

TO FIX this issue in you Unity build settings change from web to android or ios… that should of worked.

p.s. I am also looking for collaborators on plug-ins and or games for blind / VI please PM me.

@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 ??

You can use this.
https://github.com/mahirgul/GoogleTTSFor.Net