2012-02-29 09:19:54 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Speech.Synthesis;
|
|
|
|
|
|
|
|
|
|
namespace ArdupilotMega
|
|
|
|
|
{
|
|
|
|
|
public class Speech
|
|
|
|
|
{
|
|
|
|
|
SpeechSynthesizer _speechwindows;
|
|
|
|
|
System.Diagnostics.Process _speechlinux;
|
|
|
|
|
|
2012-03-01 09:27:03 -04:00
|
|
|
|
System.Speech.Synthesis.SynthesizerState _state = SynthesizerState.Ready;
|
|
|
|
|
|
2012-02-29 09:19:54 -04:00
|
|
|
|
bool MONO = false;
|
|
|
|
|
|
|
|
|
|
public SynthesizerState State {
|
|
|
|
|
get {
|
|
|
|
|
if (MONO)
|
|
|
|
|
{
|
2012-03-01 09:27:03 -04:00
|
|
|
|
return _state;
|
2012-02-29 09:19:54 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return _speechwindows.State;
|
|
|
|
|
}
|
2012-03-01 09:27:03 -04:00
|
|
|
|
}
|
2012-02-29 09:19:54 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Speech()
|
|
|
|
|
{
|
|
|
|
|
var t = Type.GetType("Mono.Runtime");
|
|
|
|
|
MONO = (t != null);
|
|
|
|
|
|
|
|
|
|
if (MONO)
|
|
|
|
|
{
|
2012-03-01 09:27:03 -04:00
|
|
|
|
_state = SynthesizerState.Ready;
|
2012-02-29 09:19:54 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_speechwindows = new SpeechSynthesizer();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SpeakAsync(string text)
|
|
|
|
|
{
|
|
|
|
|
if (MONO)
|
|
|
|
|
{
|
2012-03-01 09:27:03 -04:00
|
|
|
|
if (_speechlinux == null || _speechlinux.HasExited)
|
|
|
|
|
{
|
|
|
|
|
_state = SynthesizerState.Speaking;
|
|
|
|
|
_speechlinux = new System.Diagnostics.Process();
|
|
|
|
|
_speechlinux.StartInfo.FileName = "echo " + text + " | festival --tts";
|
|
|
|
|
_speechlinux.Start();
|
|
|
|
|
_speechlinux.Exited += new EventHandler(_speechlinux_Exited);
|
|
|
|
|
}
|
2012-02-29 09:19:54 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_speechwindows.SpeakAsync(text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-01 09:27:03 -04:00
|
|
|
|
void _speechlinux_Exited(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_state = SynthesizerState.Ready;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-29 09:19:54 -04:00
|
|
|
|
public void SpeakAsyncCancelAll()
|
|
|
|
|
{
|
|
|
|
|
if (MONO)
|
|
|
|
|
{
|
2012-03-01 09:27:03 -04:00
|
|
|
|
_speechlinux.Close();
|
|
|
|
|
_state = SynthesizerState.Ready;
|
2012-02-29 09:19:54 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_speechwindows.SpeakAsyncCancelAll();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|