ardupilot/Tools/ArdupilotMegaPlanner/Utilities/Speech.cs
Michael Oborne 4e7fe5ec5c APM Planner 1.1.94
Fix Issue 668 - typo
Fix issue 666 - now defaults to mav 1.0 planner
Fix Issue 665 - mavlink 1.0 is now default
Fix Issue 663 - increase timeout from 6 seconds to 12 seconds
Fix Issue 662 - now reads sat count for mav 1.0
Partial Issue 654 - added current to status, hud still wip
Fix Issue 648 - add validation to value
Fix Issue 638 - add delay
Fix Issue 636 - check for version.txt in app directory
Fix config panel null bug
Add more Ardurover config options
Add Exceptions handling to video format selection
Add FORMAT_VERSION to param file ignore list
Fix NOTE param file line
Add APMRover hidden firmware upload (control-R) on firmware screen.
fix possible speach engine exception
add dataflashlog for apmrover
2012-06-27 20:46:17 +08:00

115 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Synthesis;
using log4net;
namespace ArdupilotMega.Utilities
{
public class Speech
{
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
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);
log.Info("TTS: init, mono = " + MONO);
if (MONO)
{
_state = SynthesizerState.Ready;
}
else
{
_speechwindows = new SpeechSynthesizer();
}
}
public void SpeakAsync(string text)
{
if (MONO)
{
//if (_speechlinux == null)
{
_state = SynthesizerState.Speaking;
_speechlinux = new System.Diagnostics.Process();
_speechlinux.StartInfo.RedirectStandardInput = true;
_speechlinux.StartInfo.UseShellExecute = false;
_speechlinux.StartInfo.FileName = "festival";
_speechlinux.Start();
_speechlinux.Exited += new EventHandler(_speechlinux_Exited);
log.Info("TTS: start " + _speechlinux.StartTime);
}
_state = SynthesizerState.Speaking;
_speechlinux.StandardInput.WriteLine("(SayText \"" + text + "\")");
_speechlinux.StandardInput.WriteLine("(quit)");
_speechlinux.Close();
_state = SynthesizerState.Ready;
}
else
{
_speechwindows.SpeakAsync(text);
}
log.Info("TTS: say " + text);
}
void _speechlinux_Exited(object sender, EventArgs e)
{
log.Info("TTS: exit " + _speechlinux.ExitTime);
_state = SynthesizerState.Ready;
}
public void SpeakAsyncCancelAll()
{
if (MONO)
{
try
{
if (_speechlinux != null)
_speechlinux.Close();
}
catch { }
_state = SynthesizerState.Ready;
}
else
{
try
{
_speechwindows.SpeakAsyncCancelAll();
}
catch { } // System.PlatformNotSupportedException:
}
}
}
}