This commit is contained in:
2023-11-28 11:38:59 +05:30
commit ce059d4bf6
2742 changed files with 618089 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
{
"name": "Meta.WitAi.TTS.Samples",
"rootNamespace": "",
"references": [
"GUID:8bbcefc153e1f1b4a98680670797dd16",
"GUID:1c28d8b71ced07540b7c271537363cc6"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e67ffd8913b227943835c952869d26fb
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 68d2ecf49ba62e0408b8f86acb9b103c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,269 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &3550832292187419422
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3550832292187419420}
- component: {fileID: 3550832292187419423}
- component: {fileID: 1295848615748463565}
m_Layer: 0
m_Name: TTSSpeaker
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3550832292187419420
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3550832292187419422}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 3550832292895390900}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &3550832292187419423
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3550832292187419422}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b15403450229c3a4b8455a61d6143a6d, type: 3}
m_Name:
m_EditorClassIdentifier:
presetVoiceID: CHARLIE
AudioSource: {fileID: 3550832292895390901}
_cloneAudioSource: 0
prependedText:
appendedText:
_events:
OnTextPlaybackStart:
m_PersistentCalls:
m_Calls: []
OnTextPlaybackCancelled:
m_PersistentCalls:
m_Calls: []
OnTextPlaybackFinished:
m_PersistentCalls:
m_Calls: []
OnAudioClipPlaybackReady:
m_PersistentCalls:
m_Calls: []
OnAudioClipPlaybackStart:
m_PersistentCalls:
m_Calls: []
OnAudioClipPlaybackCancelled:
m_PersistentCalls:
m_Calls: []
OnAudioClipPlaybackFinished:
m_PersistentCalls:
m_Calls: []
OnStartSpeaking:
m_PersistentCalls:
m_Calls: []
OnFinishedSpeaking:
m_PersistentCalls:
m_Calls: []
OnCancelledSpeaking:
m_PersistentCalls:
m_Calls: []
OnClipLoadBegin:
m_PersistentCalls:
m_Calls: []
OnClipLoadFailed:
m_PersistentCalls:
m_Calls: []
OnClipLoadSuccess:
m_PersistentCalls:
m_Calls: []
OnClipLoadAbort:
m_PersistentCalls:
m_Calls: []
OnClipDataQueued:
m_PersistentCalls:
m_Calls: []
OnClipDataLoadBegin:
m_PersistentCalls:
m_Calls: []
OnClipDataLoadFailed:
m_PersistentCalls:
m_Calls: []
OnClipDataLoadSuccess:
m_PersistentCalls:
m_Calls: []
OnClipDataLoadAbort:
m_PersistentCalls:
m_Calls: []
OnClipDataPlaybackReady:
m_PersistentCalls:
m_Calls: []
OnClipDataPlaybackStart:
m_PersistentCalls:
m_Calls: []
OnClipDataPlaybackFinished:
m_PersistentCalls:
m_Calls: []
OnClipDataPlaybackCancelled:
m_PersistentCalls:
m_Calls: []
OnPlaybackQueueBegin:
m_PersistentCalls:
m_Calls: []
OnPlaybackQueueComplete:
m_PersistentCalls:
m_Calls: []
_ttsService: {fileID: 0}
--- !u!114 &1295848615748463565
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3550832292187419422}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 81f17bb00ee9f68428d962165826f2fd, type: 3}
m_Name:
m_EditorClassIdentifier:
_maxTextLength: 250
--- !u!1 &3550832292895390903
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3550832292895390900}
- component: {fileID: 3550832292895390901}
m_Layer: 0
m_Name: Voice
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3550832292895390900
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3550832292895390903}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 2, y: 1.665, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 3550832292187419420}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!82 &3550832292895390901
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3550832292895390903}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 0}
m_PlayOnAwake: 0
m_Volume: 1
m_Pitch: 1
Loop: 0
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 500
Pan2D: 0
rolloffMode: 0
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
panLevelCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
spreadCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
reverbZoneMixCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 45fe3f4c7b67f4d4c83f7c1d3c8f1a50
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e264fcb4f1c2dc248bacd7a1f80da833
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,175 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &4852061571279439017
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4852061571279439020}
- component: {fileID: 4852061571279439023}
- component: {fileID: 3627599131962939471}
- component: {fileID: 4852061571279439022}
m_Layer: 0
m_Name: TTSWit
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4852061571279439020
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4852061571279439017}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &4852061571279439023
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4852061571279439017}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a6b3124b830442d45b9f357ff99b152f, type: 3}
m_Name:
m_EditorClassIdentifier:
_events:
OnClipCreated:
m_PersistentCalls:
m_Calls: []
OnClipUnloaded:
m_PersistentCalls:
m_Calls: []
Stream:
OnStreamBegin:
m_PersistentCalls:
m_Calls: []
OnStreamReady:
m_PersistentCalls:
m_Calls: []
OnStreamClipUpdate:
m_PersistentCalls:
m_Calls: []
OnStreamComplete:
m_PersistentCalls:
m_Calls: []
OnStreamCancel:
m_PersistentCalls:
m_Calls: []
OnStreamError:
m_PersistentCalls:
m_Calls: []
Download:
OnDownloadBegin:
m_PersistentCalls:
m_Calls: []
OnDownloadSuccess:
m_PersistentCalls:
m_Calls: []
OnDownloadCancel:
m_PersistentCalls:
m_Calls: []
OnDownloadError:
m_PersistentCalls:
m_Calls: []
RequestSettings:
configuration: {fileID: 11400000, guid: 8ca721df475c92e4ca9167b74de4b2f6, type: 2}
audioType: 0
audioStream: 1
audioStreamReadyDuration: 0.1
audioStreamChunkLength: 5
audioStreamPreloadCount: 3
_presetVoiceSettings:
- settingsID: CHARLIE
voice: Charlie
style: default
speed: 100
pitch: 100
gain: 50
- settingsID: REBECCA
voice: Rebecca
style: default
speed: 100
pitch: 100
gain: 50
- settingsID: COOPER
voice: Cooper
style: default
speed: 100
pitch: 100
gain: 50
- settingsID: VAMPIRE
voice: Vampire
style: default
speed: 100
pitch: 100
gain: 50
- settingsID: PROSPECTOR
voice: Prospector
style: default
speed: 100
pitch: 100
gain: 50
--- !u!114 &3627599131962939471
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4852061571279439017}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1d60dcb6d02034b4b96284db469db5e3, type: 3}
m_Name:
m_EditorClassIdentifier:
ClipLimit: 1
ClipCapacity: 100
RamLimit: 0
RamCapacity: 20000
--- !u!114 &4852061571279439022
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4852061571279439017}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b0ffdd015bcb8ea41bb96f19a723bf7d, type: 3}
m_Name:
m_EditorClassIdentifier:
_diskPath: TTS/
_defaultSettings:
DiskCacheLocation: 0
_events:
OnStreamBegin:
m_PersistentCalls:
m_Calls: []
OnStreamReady:
m_PersistentCalls:
m_Calls: []
OnStreamClipUpdate:
m_PersistentCalls:
m_Calls: []
OnStreamComplete:
m_PersistentCalls:
m_Calls: []
OnStreamCancel:
m_PersistentCalls:
m_Calls: []
OnStreamError:
m_PersistentCalls:
m_Calls: []

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: a89561c2ba096ad4dbf37bbb423d6f3c
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 748ff8d1d0d4814429b86058a56a3ee4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 79647fe399cbd69458a2728d01b2f739
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5e581f7e133ba2048995048327a1ef85
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,89 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/
using Meta.WitAi.TTS.Data;
using Meta.WitAi.TTS.Integrations;
using UnityEngine;
using UnityEngine.UI;
namespace Meta.WitAi.TTS.Samples
{
public class TTSCacheToggle : MonoBehaviour
{
// UI references
[SerializeField] private TTSDiskCache _diskCache;
[SerializeField] private Text _cacheLabel;
[SerializeField] private Button _button;
// Current disk cache location
private TTSDiskCacheLocation _cacheLocation = (TTSDiskCacheLocation) (-1);
// Add listeners
private void OnEnable()
{
// Obtain disk cache if possible
if (_diskCache == null)
{
_diskCache = GameObject.FindObjectOfType<TTSDiskCache>();
}
// Reset location text
RefreshLocation();
_button.onClick.AddListener(ToggleCache);
}
// Current disk cache location
private TTSDiskCacheLocation GetCurrentCacheLocation() => _diskCache == null ? TTSDiskCacheLocation.Stream : _diskCache.DiskCacheDefaultSettings.DiskCacheLocation;
// Check for changes
private void Update()
{
if (_cacheLocation != GetCurrentCacheLocation())
{
RefreshLocation();
}
}
// Refresh location & button text
private void RefreshLocation()
{
_cacheLocation = GetCurrentCacheLocation();
_cacheLabel.text = $"Disk Cache: {_cacheLocation}";
}
// Remove listeners
private void OnDisable()
{
_button.onClick.RemoveListener(ToggleCache);
}
// Toggle cache
public void ToggleCache()
{
// Toggle to next option
TTSDiskCacheLocation cacheLocation = GetCurrentCacheLocation();
switch (cacheLocation)
{
case TTSDiskCacheLocation.Stream:
cacheLocation = TTSDiskCacheLocation.Temporary;
break;
case TTSDiskCacheLocation.Temporary:
cacheLocation = TTSDiskCacheLocation.Persistent;
break;
case TTSDiskCacheLocation.Persistent:
cacheLocation = TTSDiskCacheLocation.Preload;
break;
default:
cacheLocation = TTSDiskCacheLocation.Stream;
break;
}
// Set next option
_diskCache.DiskCacheDefaultSettings.DiskCacheLocation = cacheLocation;
// Clear runtime cache
TTSService.Instance.UnloadAll();
// Refresh location
RefreshLocation();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e7aad95c862d94f4f912114f5fd46959
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/
using UnityEngine;
using UnityEngine.UI;
namespace Meta.WitAi.TTS.Samples
{
public class TTSErrorText : MonoBehaviour
{
// Label
[SerializeField] private Text _errorLabel;
// Current error response
private string _error = string.Empty;
// Add listeners
private void Update()
{
if (TTSService.Instance != null)
{
string invalidError = TTSService.Instance.GetInvalidError();
if (!string.Equals(invalidError, _error))
{
_error = invalidError;
if (string.IsNullOrEmpty(_error))
{
_errorLabel.text = string.Empty;
}
else
{
_errorLabel.text = $"TTS Service Error: {_error}";
}
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1f9580bff99ab114d85ccce9a75b067b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,100 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/
using System;
using UnityEngine;
using UnityEngine.UI;
using Meta.WitAi.TTS.Utilities;
namespace Meta.WitAi.TTS.Samples
{
public class TTSSpeakerInput : MonoBehaviour
{
[SerializeField] private Text _title;
[SerializeField] private InputField _input;
[SerializeField] private TTSSpeaker _speaker;
[SerializeField] private Button _stopButton;
[SerializeField] private Button _speakButton;
[SerializeField] private Button _speakQueuedButton;
[SerializeField] private string _dateId = "[DATE]";
[SerializeField] private string[] _queuedText;
// States
private bool _loading;
private bool _speaking;
// Add delegates
private void OnEnable()
{
RefreshButtons();
_stopButton.onClick.AddListener(StopClick);
_speakButton.onClick.AddListener(SpeakClick);
_speakQueuedButton.onClick.AddListener(SpeakQueuedClick);
}
// Stop click
private void StopClick() => _speaker.Stop();
// Speak phrase click
private void SpeakClick() => _speaker.Speak(FormatText(_input.text));
// Speak queued phrase click
private void SpeakQueuedClick()
{
foreach (var text in _queuedText)
{
_speaker.SpeakQueued(FormatText(text));
}
_speaker.SpeakQueued(FormatText(_input.text));
}
// Format text with current datetime
private string FormatText(string text)
{
string result = text;
if (result.Contains(_dateId))
{
DateTime now = DateTime.Now;
string dateString = $"{now.ToLongDateString()} at {now.ToShortTimeString()}";
result = text.Replace(_dateId, dateString);
}
return result;
}
// Remove delegates
private void OnDisable()
{
_stopButton.onClick.RemoveListener(StopClick);
_speakButton.onClick.RemoveListener(SpeakClick);
_speakQueuedButton.onClick.RemoveListener(SpeakQueuedClick);
}
// Preset text fields
private void Update()
{
// On preset voice id update
if (!string.Equals(_title.text, _speaker.presetVoiceID))
{
_title.text = _speaker.presetVoiceID;
_input.placeholder.GetComponent<Text>().text = $"Write something to say in {_speaker.presetVoiceID}'s voice";
}
// On state changes
if (_loading != _speaker.IsLoading)
{
_loading = _speaker.IsLoading;
RefreshButtons();
}
if (_speaking != _speaker.IsSpeaking)
{
_speaking = _speaker.IsSpeaking;
RefreshButtons();
}
}
// Refresh interactable based on states
private void RefreshButtons()
{
_stopButton.interactable = _loading || _speaking;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a57b9d9fb2760434e859220f24690a1e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,72 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/
using System.Text;
using Meta.WitAi.TTS.Data;
using UnityEngine;
using UnityEngine.UI;
using Meta.WitAi.TTS.Utilities;
namespace Meta.WitAi.TTS.Samples
{
public class TTSStatusLabel : MonoBehaviour
{
[SerializeField] private TTSSpeaker _speaker;
[SerializeField] private Text _label;
private void OnEnable()
{
RefreshLabel();
_speaker.Events.OnClipDataLoadBegin.AddListener(OnClipRefresh);
_speaker.Events.OnClipDataLoadAbort.AddListener(OnClipRefresh);
_speaker.Events.OnClipDataLoadFailed.AddListener(OnClipRefresh);
_speaker.Events.OnClipDataLoadSuccess.AddListener(OnClipRefresh);
_speaker.Events.OnClipDataQueued.AddListener(OnClipRefresh);
_speaker.Events.OnClipDataPlaybackReady.AddListener(OnClipRefresh);
_speaker.Events.OnClipDataPlaybackStart.AddListener(OnClipRefresh);
_speaker.Events.OnClipDataPlaybackFinished.AddListener(OnClipRefresh);
_speaker.Events.OnClipDataPlaybackCancelled.AddListener(OnClipRefresh);
}
private void OnClipRefresh(TTSClipData clipData)
{
RefreshLabel();
}
private void OnDisable()
{
_speaker.Events.OnClipDataQueued.RemoveListener(OnClipRefresh);
_speaker.Events.OnClipDataLoadBegin.RemoveListener(OnClipRefresh);
_speaker.Events.OnClipDataLoadAbort.RemoveListener(OnClipRefresh);
_speaker.Events.OnClipDataLoadFailed.RemoveListener(OnClipRefresh);
_speaker.Events.OnClipDataLoadSuccess.RemoveListener(OnClipRefresh);
_speaker.Events.OnClipDataPlaybackReady.RemoveListener(OnClipRefresh);
_speaker.Events.OnClipDataPlaybackStart.RemoveListener(OnClipRefresh);
_speaker.Events.OnClipDataPlaybackFinished.RemoveListener(OnClipRefresh);
_speaker.Events.OnClipDataPlaybackCancelled.RemoveListener(OnClipRefresh);
}
private void RefreshLabel()
{
StringBuilder status = new StringBuilder();
if (_speaker.SpeakingClip != null)
{
status.AppendLine($"Speaking: {_speaker.IsSpeaking}");
}
int index = 0;
foreach (var clip in _speaker.QueuedClips)
{
status.Insert(0, $"Queue[{index}]: {clip.loadState.ToString()}\n");
index++;
}
if (status.Length > 0)
{
status.Remove(status.Length - 1, 1);
}
_label.text = status.ToString();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 443d56f5ec5b41c4aa647a2350247db1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,83 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/
using UnityEngine;
using UnityEngine.UI;
using Meta.WitAi.TTS.Integrations;
namespace Meta.WitAi.TTS.Samples
{
public class TTSStreamToggle : MonoBehaviour
{
// UI references
[SerializeField] private TTSWit _service;
[SerializeField] private Text _label;
[SerializeField] private Button _button;
// Current stream
private bool _streamEnabled = true;
// Add listeners
private void OnEnable()
{
// Obtain disk cache if possible
if (_service == null)
{
_service = GameObject.FindObjectOfType<TTSWit>();
}
// Log for missing service
if (_service == null)
{
VLog.E("TTS Stream Toggle - Cannot work without a TTSWit reference");
}
// Reset
RefreshStreaming();
_button.onClick.AddListener(ToggleStreaming);
}
// Remove listeners
private void OnDisable()
{
_button.onClick.RemoveListener(ToggleStreaming);
}
// Refresh location & button text
private void RefreshStreaming()
{
_streamEnabled = GetStreaming();
_label.text = $"Streaming: {(_streamEnabled ? "ON" : "OFF")}";
}
// Toggle streaming
public void ToggleStreaming()
{
SetStreaming(!_streamEnabled);
RefreshStreaming();
}
// Get streaming option from service
private bool GetStreaming()
{
return _service && _service.RequestSettings.audioStream;
}
// Set streaming option to
private void SetStreaming(bool toStreaming)
{
if (_service != null)
{
_service.RequestSettings.audioStream = toStreaming;
}
}
// Update if changed externally
private void Update()
{
if (_streamEnabled != GetStreaming())
{
RefreshStreaming();
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 62fa707a35782fb4dafd0da34ea548a1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
Welcome to Voice SDK Text-To-Speech!
The following are phrases to be auto-loaded.
Hi, how are you?
I am great! Thank you for asking!
Would you mind repeating that?
I actually cannot hear you right now.
Hmmm
Well that is interesting!
My favorite color is green.
My favorite color is purple.
Sentence one begins with a few words and then ends with an ellipsis... Does sentence two start with two spaces and end with a question mark? Sentence three also starts with two spaces, has a comma; has a semicolon and ends with two exclamation points!! A sentence with a semicolon; may be used as well.

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c94bdcb6d297dfe41a49608ed6309ab9
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: