Ardupilot2/Tools/ArdupilotMegaPlanner/Speech.cs
Michael Oborne ee5e331f3c APM Planner 1.1.45
add tcp and udp port remeber issue 533
add udp listern wait issue 534
fix wp receive on mono part issue 530
allow logging of unknown packets mav 0.9
do_speed_change fix issue 531
remember last video res issue 521
fix issue 528 - ch 6 and ch 7 options
2012-03-01 21:27:03 +08:00

83 lines
2.0 KiB
C#

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;
System.Speech.Synthesis.SynthesizerState _state = SynthesizerState.Ready;
bool MONO = false;
public SynthesizerState State {
get {
if (MONO)
{
return _state;
}
else
{
return _speechwindows.State;
}
}
}
public Speech()
{
var t = Type.GetType("Mono.Runtime");
MONO = (t != null);
if (MONO)
{
_state = SynthesizerState.Ready;
}
else
{
_speechwindows = new SpeechSynthesizer();
}
}
public void SpeakAsync(string text)
{
if (MONO)
{
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);
}
}
else
{
_speechwindows.SpeakAsync(text);
}
}
void _speechlinux_Exited(object sender, EventArgs e)
{
_state = SynthesizerState.Ready;
}
public void SpeakAsyncCancelAll()
{
if (MONO)
{
_speechlinux.Close();
_state = SynthesizerState.Ready;
}
else
{
_speechwindows.SpeakAsyncCancelAll();
}
}
}
}