Im trying to use Unity (cause Im more into javascript and I don’t know any other engine/framework using it) to send string command to my mac terminal so I could use the TTS say command.
I know I should use system.diagnostics but the only thing I manage to do is opening the terminal with the following line:
I need to pass in argument (write) but I don’t find anything about it.
Using msdn doesn’t want to work so Im a bit lost.
Also, I didn’t try to make the code run after building it as a standalone but I don’t think it will change anything.
Does someone would tell me in what direction to look?
i’ll was asking myself the same thing some weeks ago and ended up write a shell script that opens the terminal and passes a string from unity.
if put in username in the paths instead of my name
using UnityEngine;
using System.Collections;
using System.Diagnostics;
using System.IO;
public class TextToSpeech
{
public static void SpeakText(string s)
{
string file = "/Users/username/Desktop/text.txt";
File.WriteAllText(file, s);
Process p = new Process();
p.StartInfo.UseShellExecute = false ;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName ="open";
p.StartInfo.Arguments = "Talk.command";
p.StartInfo.WorkingDirectory="/Users/username/Desktop";
p.StartInfo.CreateNoWindow = true;
p.Start();
}
}
which would be used as
using UnityEngine;
using System.Collections;
public class InputGUI : MonoBehaviour
{
public string textInput;
void OnGUI ()
{
textInput = GUI.TextField(new Rect(Screen.width/2 - 150, Screen.height/2 - 50, 300, 100), textInput);
if(GUI.Button(new Rect(Screen.width/2 + 50, Screen.height/2 + 60, 100, 25), "Say It"))
{
TextToSpeech.SpeakText(textInput);
}
}
}
the shell script (with .command extension) is simply
#!/bin/bash
TEXT=`cat /Users/username/Desktop/text.txt`
say -v Vicki "$TEXT"