Skip to content

Commit c4dbea4

Browse files
committed
Make the TTS package dependency optional
1 parent c105fef commit c4dbea4

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

UnityProjects/MRTKDevTemplate/Packages/packages-lock.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@
442442
"depth": 0,
443443
"source": "local",
444444
"dependencies": {
445-
"com.microsoft.mrtk.tts.windows": "1.0.4",
446445
"org.mixedrealitytoolkit.core": "3.2.2"
447446
}
448447
},

org.mixedrealitytoolkit.windowsspeech/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
77
### Changed
88

99
* Subsystems no longer register themselves on non-Windows platforms.
10+
* Made the dependency on com.microsoft.mrtk.tts.windows optional.
1011

1112
### Fixed
1213

1314
* Updated dependencies to match Unity Asset Store packages. [PR #1054](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1054)
14-
* com.microsoft.mrtk.tts.windows 1.0.4
1515
* org.mixedrealitytoolkit.core 3.2.2
1616

1717
## [3.0.3] - 2024-04-17

org.mixedrealitytoolkit.windowsspeech/MRTK.Speech.Windows.asmdef

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
"name": "com.microsoft.mixedreality.openxr",
1919
"expression": "1.5.0",
2020
"define": "MSFT_OPENXR_1_5_0_OR_NEWER"
21+
},
22+
{
23+
"name": "com.microsoft.mrtk.tts.windows",
24+
"expression": "",
25+
"define": "MSFT_TTS_WIN_PRESENT"
2126
}
2227
],
2328
"noEngineReferences": false

org.mixedrealitytoolkit.windowsspeech/Subsystems/TextToSpeech/WindowsTextToSpeechSubsystem.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
// Licensed under the BSD 3-Clause
33

44
using MixedReality.Toolkit.Subsystems;
5-
using System;
6-
using System.Runtime.InteropServices;
75
using System.Threading.Tasks;
8-
using System.Linq;
96
using UnityEngine;
107
using UnityEngine.Scripting;
118

129
#if WINDOWS_UWP
13-
using Windows.Foundation;
10+
using System;
11+
using System.Linq;
1412
using Windows.Media.SpeechSynthesis;
1513
using Windows.Storage.Streams;
1614
#endif // WINDOWS_UWP
@@ -41,7 +39,7 @@ static void Register()
4139
// Fetch subsystem metadata from the attribute.
4240
var cinfo = XRSubsystemHelpers.ConstructCinfo<WindowsTextToSpeechSubsystem, TextToSpeechSubsystemCinfo>();
4341

44-
if (!WindowsTextToSpeechSubsystem.Register(cinfo))
42+
if (!Register(cinfo))
4543
{
4644
Debug.LogError($"Failed to register the {cinfo.Name} subsystem.");
4745
}
@@ -72,6 +70,7 @@ public override void Start()
7270
#endif
7371
}
7472

73+
/// <inheritdoc/>
7574
public override void Destroy()
7675
{
7776
#if WINDOWS_UWP
@@ -85,7 +84,7 @@ public override void Destroy()
8584

8685
#region ITextToSpeechSubsystem implementation
8786

88-
#if !(WINDOWS_UWP || UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN)
87+
#if !(WINDOWS_UWP || ((UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN) && MSFT_TTS_WIN_PRESENT))
8988
private bool haveLogged = false;
9089
#endif
9190

@@ -124,7 +123,7 @@ public override async Task<bool> TrySpeak(string phrase, AudioSource audioSource
124123
sampleRate);
125124

126125
audioSource.Play();
127-
126+
128127
return true;
129128
}
130129

@@ -186,17 +185,17 @@ private async Task<byte[]> Synthesize(string phrase)
186185
}
187186

188187
return waveData;
189-
#elif (UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN)
190-
return await Task<byte[]>.Run(() =>
188+
#elif (UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN) && MSFT_TTS_WIN_PRESENT
189+
return await Task.Run(() =>
191190
{
192-
if (!Microsoft.MixedReality.Toolkit.Speech.Windows.WinRTTextToSpeechPInvokes.TrySynthesizePhraseWithCustomVoice(phrase, config.VoiceName, out IntPtr nativeData, out int length))
191+
if (!Microsoft.MixedReality.Toolkit.Speech.Windows.WinRTTextToSpeechPInvokes.TrySynthesizePhraseWithCustomVoice(phrase, config.VoiceName, out System.IntPtr nativeData, out int length))
193192
{
194193
Debug.LogError("Failed to synthesize the phrase");
195194
return null;
196195
}
197196

198197
byte[] waveData = new byte[length];
199-
Marshal.Copy(nativeData, waveData, 0, length);
198+
System.Runtime.InteropServices.Marshal.Copy(nativeData, waveData, 0, length);
200199
// We can safely free the native data.
201200
Microsoft.MixedReality.Toolkit.Speech.Windows.WinRTTextToSpeechPInvokes.FreeSynthesizedData(nativeData);
202201

org.mixedrealitytoolkit.windowsspeech/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "org.mixedrealitytoolkit.windowsspeech",
3-
"version": "3.0.4-development",
3+
"version": "3.1.0-development",
44
"description": "Speech subsystem implementation for native Windows speech APIs enables native Windows text-to-speech and speech recognition features, producing events to drive XRI interactions using speech.",
55
"displayName": "MRTK Windows Speech",
66
"msftFeatureCategory": "MRTK3",
@@ -17,7 +17,6 @@
1717
"unityRelease": "26f1",
1818
"documentationUrl": "https://www.mixedrealitytoolkit.org",
1919
"dependencies": {
20-
"com.microsoft.mrtk.tts.windows": "1.0.4",
2120
"org.mixedrealitytoolkit.core": "3.2.2"
2221
}
2322
}

0 commit comments

Comments
 (0)