// extra data 1: file path // extra data 2: device name // extra data 3: second device name public override void HotkeyTriggered() { if (audioDevice == null) { audioDevice = MainAudio.Instance.GetDevice(ExtraData2); } MainLogic.Instance.InputCallbacks.TextResultRequestOnTopCallback("Text", (bool speakCanceled, string speakInput) => { if (!speakCanceled) { try { string fileName = "tts_" + Guid.NewGuid() + ".wav"; if (speechSynthesizer == null) { speechSynthesizer = new SpeechSynthesizer(); } speechSynthesizer.SetOutputToWaveFile(fileName); speechSynthesizer.Speak(speakInput); try { speechSynthesizer?.Dispose(); } catch (Exception) { } speechSynthesizer = null; //var voices = speechSynthesizer.GetInstalledVoices(); files.Add(fileName); CachedSound sound = new CachedSound(fileName); provider = audioDevice.AssociatedEngine.PlaySound(sound); if (!String.IsNullOrWhiteSpace(ExtraData3)) { if (audioDeviceTwo == null) { audioDeviceTwo = MainAudio.Instance.GetDevice(ExtraData3); } providerTwo = audioDeviceTwo.AssociatedEngine.PlaySound(sound); } if (AdditionalExtraData != null && AdditionalExtraData.ContainsKey((int)HotkeyAdditionalDataType.DeviceThree) && !String.IsNullOrWhiteSpace(AdditionalExtraData[(int)HotkeyAdditionalDataType.DeviceThree])) { if (audioDeviceThree == null) { audioDeviceThree = MainAudio.Instance.GetDevice(AdditionalExtraData[(int)HotkeyAdditionalDataType.DeviceThree]); } providerThree = audioDeviceThree.AssociatedEngine.PlaySound(sound); } } catch (Exception ex) { } } }); }
// extra data 1: file path // extra data 2: device name // extra data 3: second device name public override void HotkeyTriggered() { if (audioDevice == null) { audioDevice = MainAudio.Instance.GetDevice(ExtraData2); } provider = audioDevice.AssociatedEngine.PlaySound(cachedSound); if (!String.IsNullOrWhiteSpace(ExtraData3)) { if (audioDeviceTwo == null) { audioDeviceTwo = MainAudio.Instance.GetDevice(ExtraData3); } providerTwo = audioDeviceTwo.AssociatedEngine.PlaySound(cachedSound); } if (AdditionalExtraData != null && AdditionalExtraData.ContainsKey((int)HotkeyAdditionalDataType.DeviceThree) && !String.IsNullOrWhiteSpace(AdditionalExtraData[(int)HotkeyAdditionalDataType.DeviceThree])) { if (audioDeviceThree == null) { audioDeviceThree = MainAudio.Instance.GetDevice(AdditionalExtraData[(int)HotkeyAdditionalDataType.DeviceThree]); } providerThree = audioDeviceThree.AssociatedEngine.PlaySound(cachedSound); } }
public static void ProcessProvider(NAudio.Wave.ISampleProvider provider, string sourceName) { if (provider == null) { return; } float[] buffer = new float[1024]; bool bContinue = true; int sampleRate = provider.WaveFormat.SampleRate; Decoders.MDC1200 mdc = new Decoders.MDC1200(sampleRate, MDCDelegate, sourceName); //Decoders.STAR star = new Decoders.STAR(sampleRate, null, RadioLog.AudioProcessing.Decoders.STAR.star_format.star_format_1_16383); while (bContinue) { int iCnt = provider.Read(buffer, 0, buffer.Length); bContinue = iCnt > 0; if (bContinue) { mdc.ProcessSamples(buffer, iCnt, true); //star.star_decoder_process_samples(buffer, iCnt); } } }