diff --git a/Assets/Cryville.EEW.Unity/TTSWorker.cs b/Assets/Cryville.EEW.Unity/TTSWorker.cs index 5227e77..667c19d 100644 --- a/Assets/Cryville.EEW.Unity/TTSWorker.cs +++ b/Assets/Cryville.EEW.Unity/TTSWorker.cs @@ -1,3 +1,4 @@ +using SpeechLib; using System; using System.Globalization; using System.Threading; @@ -5,7 +6,14 @@ using System.Threading.Tasks; namespace Cryville.EEW.Unity { class TTSWorker : Core.Audio.TTSWorker { - public TTSWorker() : base(CreateSoundPlayer()) { } + readonly SpVoiceClass _voice; + + public TTSWorker() : base(CreateSoundPlayer()) { + try { + _voice = new SpVoiceClass(); + } + catch { } + } static SoundPlayer CreateSoundPlayer() { try { @@ -16,10 +24,24 @@ namespace Cryville.EEW.Unity { } } - protected override bool IsSpeaking() => false; + protected override bool IsSpeaking() { + if (_voice == null) return false; + _voice.GetStatus(out var status, out _); + return (status.dwRunningState & (uint)SpeechRunState.SRSEIsSpeaking) != 0; + } - protected override Task Speak(CultureInfo culture, string content, CancellationToken cancellationToken) => Task.CompletedTask; + protected override Task Speak(CultureInfo culture, string content, CancellationToken cancellationToken) { + if (_voice == null) return Task.CompletedTask; + _voice.Speak( + string.Format(CultureInfo.InvariantCulture, "{1}", culture.LCID, content), + SpeechVoiceSpeakFlags.SVSFlagsAsync | SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak + ); + return Task.CompletedTask; + } - protected override void StopCurrent() { } + protected override void StopCurrent() { + if (_voice == null) return; + _voice.Skip("SENTENCE", int.MaxValue); + } } } diff --git a/Assets/Plugins/Windows/Interop.SpeechLib.dll b/Assets/Plugins/Windows/Interop.SpeechLib.dll new file mode 100644 index 0000000..c5c5fc2 Binary files /dev/null and b/Assets/Plugins/Windows/Interop.SpeechLib.dll differ diff --git a/Assets/Plugins/Windows/Interop.SpeechLib.dll.meta b/Assets/Plugins/Windows/Interop.SpeechLib.dll.meta new file mode 100644 index 0000000..9ac294d --- /dev/null +++ b/Assets/Plugins/Windows/Interop.SpeechLib.dll.meta @@ -0,0 +1,76 @@ +fileFormatVersion: 2 +guid: 17df7db50754b8f459aa29934b507000 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + : Any + second: + enabled: 0 + settings: + Exclude Android: 1 + Exclude Editor: 0 + Exclude Linux64: 1 + Exclude OSXUniversal: 1 + Exclude Win: 0 + Exclude Win64: 0 + - first: + Android: Android + second: + enabled: 0 + settings: + CPU: ARMv7 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 1 + settings: + CPU: AnyCPU + DefaultValueInitialized: true + OS: AnyOS + - first: + Standalone: Linux64 + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: OSXUniversal + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: Win + second: + enabled: 1 + settings: + CPU: x86 + - first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: x86_64 + - first: + Windows Store Apps: WindowsStoreApps + second: + enabled: 0 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: