feat: Implement TTS
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using SpeechLib;
|
||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -5,7 +6,14 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Cryville.EEW.Unity {
|
namespace Cryville.EEW.Unity {
|
||||||
class TTSWorker : Core.Audio.TTSWorker {
|
class TTSWorker : Core.Audio.TTSWorker {
|
||||||
public TTSWorker() : base(CreateSoundPlayer()) { }
|
readonly SpVoiceClass _voice;
|
||||||
|
|
||||||
|
public TTSWorker() : base(CreateSoundPlayer()) {
|
||||||
|
try {
|
||||||
|
_voice = new SpVoiceClass();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
static SoundPlayer CreateSoundPlayer() {
|
static SoundPlayer CreateSoundPlayer() {
|
||||||
try {
|
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, "<LANG LANGID=\"{0:x}\">{1}</LANG>", 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BIN
Assets/Plugins/Windows/Interop.SpeechLib.dll
Normal file
BIN
Assets/Plugins/Windows/Interop.SpeechLib.dll
Normal file
Binary file not shown.
76
Assets/Plugins/Windows/Interop.SpeechLib.dll.meta
Normal file
76
Assets/Plugins/Windows/Interop.SpeechLib.dll.meta
Normal file
@@ -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:
|
Reference in New Issue
Block a user