- Home /
Question by
djackson_unity · Apr 11, 2021 at 06:57 PM ·
textmactts
Apple/Mac Text to Speech script working in the editor but not in my build?
Hey y'all,
I'm working on a Unity project that's only ever going to run on my computer, so I have some flexibility in how it's executed. I'm using a script from the forums (this one that I modified very slightly. Right now it's working as expected in the editor, but when I make a build the text to speech isn't working.
Any ideas? Text to speech and interacting with apple's built in stuff is new to me, so please let me know if more information would be helpful too
Here's the code I'm using:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class narrationScript : MonoBehaviour
{
public string voice = "Tessa";
public int outputChannel = 48;
public UnityEvent onStartedSpeaking;
public UnityEvent onStoppedSpeaking;
System.Diagnostics.Process speechProcess;
bool wasSpeaking;
void Update()
{
bool isSpeaking = (speechProcess != null && !speechProcess.HasExited);
if (isSpeaking != wasSpeaking)
{
if (isSpeaking) onStartedSpeaking.Invoke();
else onStoppedSpeaking.Invoke();
wasSpeaking = isSpeaking;
}
}
public void Speak(string text)
{
string cmdArgs = string.Format("-v {0} [[volm 0.2]] \"{1}\"", voice, text.Replace("\"", ","));
speechProcess = System.Diagnostics.Process.Start("/usr/bin/say", cmdArgs);
}
public void Line001Method()
{
Speak("Good evening. Mine is a faint voice. Kindly tune accordingly.");
}
Comment