private void ConfigureSpeechEngine(TTSRequest request) { speech.Voice = config.getVoice(request.Language, request.Voice); /* Setting the DefaultRate is not ideal, but voice properties do not provide * the default rate, and it is currently not possible to send a reset message * to the NSSpeechSynthesizer via MonoMac. * This is a workaround that seems to suffice at the moment. */ DefaultRate = 170f; //speech.Rate = (DefaultRate + -(5 - request.Speed) * 5); speech.Rate = Scale(request.Speed, 0, 10, 130, 200); Console.WriteLine(speech.Rate); }
public ApiModule(TTSProducer producer) { Get["/"] = _ => { return HttpStatusCode.NotFound; }; Get["/api"] = _ => { return HttpStatusCode.NotFound; }; Get["/status"] = _ => { return View["Status"]; }; Get["/api/test"] = _ => { return View["Test"]; }; Get["/api/tts"] = _ => { return HttpStatusCode.NotFound; }; Post["/api/tts", true] = async (parameters, context) => { // bind model var ttsrequest = this.Bind<TTSRequest>(); if (ttsrequest.Text.Trim().Length == 0) { return HttpStatusCode.BadRequest; } // queue the tts request producer.QueueRequest(ttsrequest); return HttpStatusCode.OK; }; Post["/api/reset", true] = async (parameters, context) => { var ttsrequest = new TTSRequest(); ttsrequest.Interrupt = true; ttsrequest.Reset = true; producer.QueueRequest(ttsrequest); return HttpStatusCode.OK; }; }
public ApiModule(TTSProducer producer) { Get["/"] = _ => { return(HttpStatusCode.NotFound); }; Get["/api"] = _ => { return(HttpStatusCode.NotFound); }; Get["/status"] = _ => { return(View["Status"]); }; Get["/api/test"] = _ => { return(View["Test"]); }; Get["/api/tts"] = _ => { return(HttpStatusCode.NotFound); }; Post["/api/tts", true] = async(parameters, context) => { // bind model var ttsrequest = this.Bind <TTSRequest>(); if (ttsrequest.Text.Trim().Length == 0) { return(HttpStatusCode.BadRequest); } // queue the tts request producer.QueueRequest(ttsrequest); return(HttpStatusCode.OK); }; Post["/api/reset", true] = async(parameters, context) => { var ttsrequest = new TTSRequest(); ttsrequest.Interrupt = true; ttsrequest.Reset = true; producer.QueueRequest(ttsrequest); return(HttpStatusCode.OK); }; }
public void QueueRequest(TTSRequest request) { queue.Enqueue(request); }
protected override void OnLoad(EventArgs e) { Visible = false; ShowInTaskbar = false; base.OnLoad(e); /* * Get all installed voices * */ var voices = speech.GetInstalledVoices(); string voice = ""; foreach (InstalledVoice v in voices) { if (v.Enabled) { //voice = v.VoiceInfo.Name; Console.WriteLine(v.VoiceInfo.Name); } } queuetimer = new System.Timers.Timer(250); queuetimer.Elapsed += (object sender, ElapsedEventArgs ev) => { TTSRequest r; if (Queue.TryDequeue(out r)) { Console.WriteLine("dequeing off of concurrent queue..."); if (r.Interrupt) { // stop current TTS if (IsSpeaking) { //speech.StopSpeaking(); } if (IsSounding) { //sound.Stop(); if (sound.PlaybackState == PlaybackState.Playing) { sound.Stop(); } } // clear queue SpeechQueue.Clear(); } SpeechQueue.Enqueue(r); RequestCount++; } var eventdata = new Hashtable(); eventdata.Add("ProcessedRequests", RequestCount); eventdata.Add("QueuedRequests", SpeechQueue.Count); eventdata.Add("IsSpeaking", IsSounding); InstrumentationEvent blam = new InstrumentationEvent(); blam.EventName = "status"; blam.Data = eventdata; NotifyGui(blam.EventMessage()); }; // when this timer fires, it will pull off of the speech queue and speak it // the long delay also adds a little pause between tts requests. speechtimer = new System.Timers.Timer(1000); speechtimer.Elapsed += (object sender, ElapsedEventArgs ev) => { if (IsSpeaking.Equals(false)) { if (SpeechQueue.Count > 0) { TTSRequest r = SpeechQueue.Dequeue(); Console.WriteLine("dequeuing off of speech queue"); IsSpeaking = true; speechtimer.Enabled = false; //speech.SpeakAsync(r.Text); //using (speech = new SpeechSynthesizer()) { speech = new SpeechSynthesizer(); speech.SpeakCompleted += speech_SpeakCompleted; format = new SpeechAudioFormatInfo(EncodingFormat.ALaw, 8000, 8, 1, 1, 2, null); //format = new SpeechAudioFormatInfo(11025, AudioBitsPerSample.Sixteen, AudioChannel.Mono); // var si = speech.GetType().GetMethod("SetOutputStream", BindingFlags.Instance | BindingFlags.NonPublic); stream = new MemoryStream(); //si.Invoke(speech, new object[] { stream, format, true, true }); //speech.SetOutputToWaveStream(stream); speech.SetOutputToAudioStream(stream, format); speech.SelectVoice(config.getVoice(r.Language, r.Voice)); int rate = (r.Speed * 2 - 10); Console.WriteLine(rate); try { speech.Rate = rate; } catch (ArgumentOutOfRangeException ex) { speech.Rate = 0; } speech.SpeakAsync(r.Text); //} synthesis.WaitOne(); speech.SpeakCompleted -= speech_SpeakCompleted; speech.SetOutputToNull(); speech.Dispose(); //IsSpeaking = false; IsSounding = true; stream.Position = 0; //WaveFormat.CreateCustomFormat(WaveFormatEncoding.WmaVoice9, 11025, 1, 16000, 2, 16) using (RawSourceWaveStream reader = new RawSourceWaveStream(stream, WaveFormat.CreateALawFormat(8000, 1))) { WaveStream ws = WaveFormatConversionStream.CreatePcmStream(reader); //var waveProvider = new MultiplexingWaveProvider(new IWaveProvider[] { ws }, 4); //waveProvider.ConnectInputToOutput(0, 3); sound = new WaveOutEvent(); // set output device *before* init Console.WriteLine("Output Device: " + OutputDeviceId); sound.DeviceNumber = OutputDeviceId; sound.Init(ws); //sound.Init(waveProvider); sound.PlaybackStopped += output_PlaybackStopped; // Console.WriteLine("playing here " + ws.Length); sound.Play(); } playback.WaitOne(); //IsSounding = false; speechtimer.Enabled = true; } } }; queuetimer.Enabled = true; queuetimer.Start(); speechtimer.Enabled = true; speechtimer.Start(); InitHTTPServer(); }
private void ConfigureSpeechEngine(TTSRequest request) { speech.Voice = config.getVoice (request.Language, request.Voice); /* Setting the DefaultRate is not ideal, but voice properties do not provide * the default rate, and it is currently not possible to send a reset message * to the NSSpeechSynthesizer via MonoMac. * This is a workaround that seems to suffice at the moment. */ DefaultRate = 170f; //speech.Rate = (DefaultRate + -(5 - request.Speed) * 5); speech.Rate = Scale (request.Speed, 0, 10, 130, 200); Console.WriteLine (speech.Rate); }
public override void FinishedLaunching(NSObject notification) { // Configure logger string path = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "log4net.config"); XmlConfigurator.ConfigureAndWatch(new FileInfo(path)); logger.Info("Ventriliquest 1.0 Starting up..."); // Get list of available audio out devices xamspeech ham = new xamspeech(); OutputDevices = ham.GetDevices(); // Setup UI statusMenu = new NSMenu(); statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem(30); var outputItem = new NSMenuItem("Output Device", (a, b) => { }); var deviceList = new NSMenu(); outputItem.Submenu = deviceList; OutputDeviceUID = "Built-in Output"; foreach (var entry in OutputDevices) { var test = new NSMenuItem(entry.Key.ToString(), (a, b) => { foreach (NSMenuItem item in deviceList.ItemArray()) { item.State = NSCellStateValue.Off; } NSMenuItem theItem = (NSMenuItem)a; theItem.State = NSCellStateValue.On; config.OutputDevice = theItem.Title; foreach (var e in OutputDevices) { if (e.Key.ToString().Equals(theItem.Title)) { OutputDeviceUID = e.Value.ToString(); } } }); if (entry.Key.ToString().Equals(config.OutputDevice)) { test.State = NSCellStateValue.On; OutputDeviceUID = entry.Value.ToString(); } deviceList.AddItem(test); } var daItem = new NSMenuItem("Local Connections Only", (a, b) => { NSMenuItem theItem = (NSMenuItem)a; if (theItem.State == NSCellStateValue.On) { config.LocalOnly = false; theItem.State = NSCellStateValue.Off; } else { config.LocalOnly = true; theItem.State = NSCellStateValue.On; } }); if (config.LocalOnly) { daItem.State = NSCellStateValue.On; } var quitItem = new NSMenuItem("Quit", (a, b) => Shutdown()); var voiceconfigItem = new NSMenuItem("Voice Configuration", (a, b) => Process.Start("http://127.0.0.1:7888/config")); statusMenu.AddItem(new NSMenuItem("Version: 1.1")); statusMenu.AddItem(outputItem); statusMenu.AddItem(daItem); statusMenu.AddItem(voiceconfigItem); statusMenu.AddItem(quitItem); statusItem.Menu = statusMenu; statusItem.Image = NSImage.ImageNamed("tts-1.png"); statusItem.AlternateImage = NSImage.ImageNamed("tts-2.png"); statusItem.HighlightMode = true; speechdelegate.DidComplete += delegate { synthesis.Set(); }; sounddelegate.DidComplete += delegate { playback.Set(); IsSounding = false; IsSpeaking = false; sound.Dispose(); }; speech.Delegate = speechdelegate; queuetimer = new System.Timers.Timer(250); queuetimer.Elapsed += (object sender, ElapsedEventArgs e) => { TTSRequest r; if (Queue.TryDequeue(out r)) { if (r.Interrupt) { // stop current TTS NSApplication.SharedApplication.InvokeOnMainThread(delegate { if (IsSpeaking) { speech.StopSpeaking(); } if (IsSounding) { sound.Stop(); } }); // clear queue SpeechQueue.Clear(); } if (!r.Reset) { SpeechQueue.Enqueue(r); } RequestCount++; } var eventdata = new Hashtable(); eventdata.Add("ProcessedRequests", RequestCount); eventdata.Add("QueuedRequests", SpeechQueue.Count); eventdata.Add("IsSpeaking", IsSpeaking); InstrumentationEvent ev = new InstrumentationEvent(); ev.EventName = "status"; ev.Data = eventdata; NotifyGui(ev.EventMessage()); }; // when this timer fires, it will pull off of the speech queue and speak it // the 1000ms delay also adds a little pause between tts requests. speechtimer = new System.Timers.Timer(250); speechtimer.Elapsed += (object sender, ElapsedEventArgs e) => { if (IsSpeaking.Equals(false)) { if (SpeechQueue.Count > 0) { TTSRequest r = SpeechQueue.Dequeue(); IsSpeaking = true; speechtimer.Enabled = false; var oink = Path.Combine(audiopath, "temp.aiff"); NSApplication.SharedApplication.InvokeOnMainThread(delegate { ConfigureSpeechEngine(r); speech.StartSpeakingStringtoURL(r.Text, new NSUrl(oink, false)); }); synthesis.WaitOne(); NSApplication.SharedApplication.InvokeOnMainThread(delegate { IsSounding = true; sound = new NSSound(Path.Combine(audiopath, "temp.aiff"), false); sound.Delegate = sounddelegate; //if(OutputDeviceUID != "Default") { sound.PlaybackDeviceID = OutputDeviceUID; //} sound.Play(); }); playback.WaitOne(); IsSounding = false; speechtimer.Enabled = true; } } }; queuetimer.Enabled = true; queuetimer.Start(); speechtimer.Enabled = true; speechtimer.Start(); InitHTTPServer(); }