Initialer Upload neues Unity-Projekt
This commit is contained in:
8
Assets/Oculus/Voice/Samples/TTSVoices/Audio.meta
Normal file
8
Assets/Oculus/Voice/Samples/TTSVoices/Audio.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a055de36d1eb600438a9672f8a87aa4f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Oculus/Voice/Samples/TTSVoices/Audio/AsyncComplete.wav
(Stored with Git LFS)
Normal file
BIN
Assets/Oculus/Voice/Samples/TTSVoices/Audio/AsyncComplete.wav
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -0,0 +1,22 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 08c3f8e8283d6b94880e22280a446d1b
|
||||
AudioImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 6
|
||||
defaultSettings:
|
||||
loadType: 0
|
||||
sampleRateSetting: 0
|
||||
sampleRateOverride: 44100
|
||||
compressionFormat: 1
|
||||
quality: 1
|
||||
conversionMode: 0
|
||||
platformSettingOverrides: {}
|
||||
forceToMono: 0
|
||||
normalize: 1
|
||||
preloadAudioData: 1
|
||||
loadInBackground: 0
|
||||
ambisonic: 0
|
||||
3D: 1
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Oculus/Voice/Samples/TTSVoices/Materials.meta
Normal file
8
Assets/Oculus/Voice/Samples/TTSVoices/Materials.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b2aba7c73993fe740a6d88f6a3ebe8cc
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
84
Assets/Oculus/Voice/Samples/TTSVoices/Materials/Skybox.mat
Normal file
84
Assets/Oculus/Voice/Samples/TTSVoices/Materials/Skybox.mat
Normal file
@ -0,0 +1,84 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Skybox
|
||||
m_Shader: {fileID: 106, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_ShaderKeywords: _SUNDISK_HIGH_QUALITY
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats:
|
||||
- _AtmosphereThickness: 1.54
|
||||
- _BumpScale: 1
|
||||
- _Cutoff: 0.5
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _Exposure: 1
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.5
|
||||
- _GlossyReflections: 1
|
||||
- _Metallic: 0
|
||||
- _Mode: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _SunDisk: 2
|
||||
- _SunSize: 0
|
||||
- _SunSizeConvergence: 5
|
||||
- _UVSec: 0
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _GroundColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _SkyTint: {r: 0.3773585, g: 0.2076738, b: 0, a: 1}
|
||||
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb25191ecaaa6864bb08fe4b3eea748c
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Oculus/Voice/Samples/TTSVoices/Prefabs.meta
Normal file
8
Assets/Oculus/Voice/Samples/TTSVoices/Prefabs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a27fd263bcf896a4e84c59189d0e420f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Oculus/Voice/Samples/TTSVoices/Prefabs/TTSSpeaker.prefab
(Stored with Git LFS)
Normal file
BIN
Assets/Oculus/Voice/Samples/TTSVoices/Prefabs/TTSSpeaker.prefab
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7e41a5ed3743804eacae1e009586e72
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Oculus/Voice/Samples/TTSVoices/Prefabs/TTSSpeakerPanel.prefab
(Stored with Git LFS)
Normal file
BIN
Assets/Oculus/Voice/Samples/TTSVoices/Prefabs/TTSSpeakerPanel.prefab
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ff7fbfe0243d604ea0d362d82d4baf2
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Oculus/Voice/Samples/TTSVoices/Prefabs/TTSWit.prefab
(Stored with Git LFS)
Normal file
BIN
Assets/Oculus/Voice/Samples/TTSVoices/Prefabs/TTSWit.prefab
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e919abfe68b0314aa3fa156a83435f2
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Oculus/Voice/Samples/TTSVoices/Scripts.meta
Normal file
8
Assets/Oculus/Voice/Samples/TTSVoices/Scripts.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d3b5c828cbc6c346a313c6a6ba35cac
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "Meta.Voice.Samples.TTSVoices",
|
||||
"references": [
|
||||
"GUID:8bbcefc153e1f1b4a98680670797dd16",
|
||||
"GUID:1c28d8b71ced07540b7c271537363cc6"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4ae70944d4b73049b04afa3a1e912a7
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,397 @@
|
||||
/*
|
||||
* 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.Collections.Generic;
|
||||
using Meta.WitAi;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Meta.Voice.Samples.TTSVoices
|
||||
{
|
||||
public class SimpleDropdownIndexEvent : UnityEvent<int> {}
|
||||
public class SimpleDropdownOptionEvent : UnityEvent<string> {}
|
||||
|
||||
/// <summary>
|
||||
/// A dropdown ui interface that uses 'UnityEngine.Text' labels and
|
||||
/// builds content via a load method that accepts a list of strings.
|
||||
/// </summary>
|
||||
public class SimpleDropdownList : MonoBehaviour
|
||||
{
|
||||
[Header("Dropdown Toggle UI")]
|
||||
[SerializeField] [Tooltip("Button used for speaker dropdown toggle")]
|
||||
private Toggle _dropdownToggle;
|
||||
[SerializeField] [Tooltip("Button arrow image showing open or closed")]
|
||||
private Transform _dropdownButtonArrowImage;
|
||||
[SerializeField] [Tooltip("Button text to be displayed without option selected")]
|
||||
public string DropdownToggleUnselectedText = "...";
|
||||
|
||||
[Header("Dropdown List UI")]
|
||||
[SerializeField] [Tooltip("Canvas used for dropdown popup")]
|
||||
private CanvasGroup _dropdownListPopup;
|
||||
[SerializeField] [Tooltip("Dropdown scroll rect used for the dropdown list")]
|
||||
private ScrollRect _dropdownListScrollRect;
|
||||
[SerializeField] [Tooltip("Prefab used for canvas dropdown list")]
|
||||
private Toggle _dropdownListCellPrefab;
|
||||
[SerializeField] [Tooltip("Additional text padding for dropdown cells")]
|
||||
private float _dropdownCellTextPadding = 2f;
|
||||
|
||||
[SerializeField] [Tooltip("All available options for this dropdown")]
|
||||
private string[] _options;
|
||||
public string[] Options => _options;
|
||||
|
||||
[Header("Dropdown Default Settings")]
|
||||
[SerializeField] [Tooltip("The current option selected")]
|
||||
private int _selectedOptionIndex = -1;
|
||||
public int SelectedOptionIndex => _selectedOptionIndex;
|
||||
|
||||
// Accessor for selected option
|
||||
public string SelectedOption
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_options != null && SelectedOptionIndex >= 0 && SelectedOptionIndex < _options.Length)
|
||||
{
|
||||
return _options[SelectedOptionIndex];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField] [Tooltip("Dropdown callback event for selection by int")]
|
||||
private SimpleDropdownIndexEvent _onIndexSelected = new SimpleDropdownIndexEvent();
|
||||
public SimpleDropdownIndexEvent OnIndexSelected => _onIndexSelected;
|
||||
|
||||
[SerializeField] [Tooltip("Dropdown callback event for selection by option")]
|
||||
private SimpleDropdownOptionEvent _onOptionSelected = new SimpleDropdownOptionEvent();
|
||||
public SimpleDropdownOptionEvent OnOptionSelected => _onOptionSelected;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the popup is currently showing or not
|
||||
/// </summary>
|
||||
public bool IsShowing { get; private set; }
|
||||
|
||||
// Data currently being used
|
||||
private List<Toggle> _cells = new List<Toggle>();
|
||||
|
||||
/// <summary>
|
||||
/// On awake, find dropdown cell
|
||||
/// </summary>
|
||||
protected virtual void Awake()
|
||||
{
|
||||
FindCellPrefab();
|
||||
}
|
||||
|
||||
// Find existing toggle if no prefab is assigned
|
||||
private void FindCellPrefab()
|
||||
{
|
||||
if (_dropdownListCellPrefab == null)
|
||||
{
|
||||
_dropdownListCellPrefab = _dropdownListScrollRect.content.GetComponentInChildren<Toggle>();
|
||||
if (_dropdownListCellPrefab != null)
|
||||
{
|
||||
_dropdownListCellPrefab.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("No Dropdown Cell Prefab Found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform dropdown setup methods
|
||||
/// </summary>
|
||||
protected virtual void Start()
|
||||
{
|
||||
// Hide
|
||||
SetShowing(false);
|
||||
// Load dropdown
|
||||
if (_options != null && _options.Length > 0)
|
||||
{
|
||||
LoadDropdown(Options);
|
||||
}
|
||||
// Force a selection refresh
|
||||
int index = _selectedOptionIndex;
|
||||
_selectedOptionIndex = index - 1;
|
||||
SelectOption(index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add toggle delegate
|
||||
/// </summary>
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
_dropdownToggle.onValueChanged.AddListener(OnToggleClick);
|
||||
}
|
||||
/// <summary>
|
||||
/// Remove toggle delegate
|
||||
/// </summary>
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
_dropdownToggle.onValueChanged.RemoveListener(OnToggleClick);
|
||||
}
|
||||
|
||||
#if ENABLE_LEGACY_INPUT_MANAGER
|
||||
/// <summary>
|
||||
/// Hide if touch outside of the scroll rect & toggle button
|
||||
/// </summary>
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (IsShowing && Input.GetMouseButtonDown(0) && _dropdownListScrollRect != null && _dropdownToggle != null)
|
||||
{
|
||||
Vector2 touchPosition = Input.mousePosition;
|
||||
if (!IsInRect(_dropdownListScrollRect.viewport, touchPosition)
|
||||
&& !IsInRect(_dropdownToggle.GetComponent<RectTransform>(), touchPosition))
|
||||
{
|
||||
SetShowing(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Check for rect
|
||||
private static bool IsInRect(RectTransform rectTransform, Vector2 touchPosition)
|
||||
{
|
||||
// No main camera or rect
|
||||
Camera cam = Camera.main;
|
||||
if (cam == null || rectTransform == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Check mouse position screen point
|
||||
return RectTransformUtility.RectangleContainsScreenPoint(rectTransform, touchPosition, cam);
|
||||
}
|
||||
#endif
|
||||
|
||||
#region LOAD
|
||||
/// <summary>
|
||||
/// Load dropdown with specified options
|
||||
/// </summary>
|
||||
/// <param name="newOptions">The options to be used</param>
|
||||
public void LoadDropdown(string[] newOptions)
|
||||
{
|
||||
// Get options
|
||||
_options = newOptions;
|
||||
|
||||
// Disable all previous cells
|
||||
foreach (var cell in _cells)
|
||||
{
|
||||
cell.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
// Setup if needed, or log error
|
||||
FindCellPrefab();
|
||||
if (_dropdownListCellPrefab == null)
|
||||
{
|
||||
VLog.W($"Cannot load {gameObject.name} without a cell prefab");
|
||||
return;
|
||||
}
|
||||
|
||||
// Iterate all options
|
||||
float height = 0f;
|
||||
int total = _options == null ? 0 : _options.Length;
|
||||
for (int c = 0; c < total; c++)
|
||||
{
|
||||
// Get existing cell if possible
|
||||
Toggle cell = c < _cells.Count ? _cells[c] : null;
|
||||
|
||||
// Instantiate if needed
|
||||
if (cell == null)
|
||||
{
|
||||
// Instantiate
|
||||
cell = Instantiate(_dropdownListCellPrefab.gameObject).GetComponent<Toggle>();
|
||||
cell.name = $"{_dropdownListCellPrefab.gameObject.name}_CELL_{c:000}";
|
||||
cell.transform.SetParent(_dropdownListScrollRect.content, false);
|
||||
|
||||
// Override cell
|
||||
if (c < _cells.Count)
|
||||
{
|
||||
_cells[c] = cell;
|
||||
}
|
||||
// Add new cell
|
||||
else
|
||||
{
|
||||
_cells.Add(cell);
|
||||
}
|
||||
}
|
||||
|
||||
// Enable & load
|
||||
cell.gameObject.SetActive(true);
|
||||
LoadCell(cell, c, _options[c], ref height);
|
||||
}
|
||||
|
||||
// Set height to content of scrolldown list
|
||||
_dropdownListScrollRect.content.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0f, height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Load a specific cell
|
||||
/// </summary>
|
||||
/// <param name="index">Cell index</param>
|
||||
/// <returns>Height of cell</returns>
|
||||
protected virtual void LoadCell(Toggle cell, int index, string option, ref float y)
|
||||
{
|
||||
// Apply name to cell
|
||||
Text cellText = cell.GetComponentInChildren<Text>();
|
||||
if (cellText != null)
|
||||
{
|
||||
cellText.text = option;
|
||||
}
|
||||
|
||||
// Apply callback to cell
|
||||
cell.onValueChanged.RemoveAllListeners();
|
||||
cell.isOn = false;
|
||||
cell.onValueChanged.AddListener((isSelected) => OnCellClick(index, isSelected));
|
||||
|
||||
// Apply width to cell
|
||||
RectTransform cellRect = cell.GetComponent<RectTransform>();
|
||||
cellRect.anchorMin = new Vector2(0f, 1f);
|
||||
cellRect.anchorMax = new Vector2(1f, 1f);
|
||||
cellRect.pivot = new Vector2(0.5f, 1f);
|
||||
cellRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _dropdownListScrollRect.content.rect.width);
|
||||
cellRect.anchoredPosition = new Vector2(0f, -y);
|
||||
|
||||
// Apply height
|
||||
float height = cellRect.rect.height;
|
||||
if (cellText != null)
|
||||
{
|
||||
float textMargin = Mathf.Max(0f, height - cellText.rectTransform.rect.height);
|
||||
height = Mathf.CeilToInt(cellText.preferredHeight + _dropdownCellTextPadding + textMargin);
|
||||
cellRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
|
||||
}
|
||||
|
||||
// Add new height
|
||||
y += height;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SELECTION
|
||||
/// <summary>
|
||||
/// Select an item in the dropdown list
|
||||
/// </summary>
|
||||
/// <param name="newIndex">The option index to be selected</param>
|
||||
public void SelectOption(int newIndex)
|
||||
{
|
||||
// Ignore if same
|
||||
if (newIndex == SelectedOptionIndex)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply new index
|
||||
_selectedOptionIndex = newIndex;
|
||||
|
||||
// Get option text
|
||||
string optionText = SelectedOption;
|
||||
|
||||
// Apply to button
|
||||
Text buttonText = _dropdownToggle.GetComponentInChildren<Text>();
|
||||
if (buttonText != null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(optionText))
|
||||
{
|
||||
buttonText.text = DropdownToggleUnselectedText;
|
||||
}
|
||||
else
|
||||
{
|
||||
buttonText.text = optionText;
|
||||
}
|
||||
}
|
||||
|
||||
// Adjust cells
|
||||
int total = _cells == null ? 0 : _cells.Count;
|
||||
for (int i = 0; i < total; i++)
|
||||
{
|
||||
_cells[i].isOn = i == SelectedOptionIndex;
|
||||
_cells[i].interactable = i != SelectedOptionIndex;
|
||||
}
|
||||
|
||||
// Call event
|
||||
OnOptionSelected?.Invoke(optionText);
|
||||
OnIndexSelected?.Invoke(SelectedOptionIndex);
|
||||
|
||||
// Selected
|
||||
if (IsShowing)
|
||||
{
|
||||
SetShowing(false);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Select option by name
|
||||
/// </summary>
|
||||
/// <param name="option">The option to be selected</param>
|
||||
public void SelectOption(string option) => SelectOption(GetOptionIndex(option));
|
||||
/// <summary>
|
||||
/// When a cell is clicked, select a specific option
|
||||
/// </summary>
|
||||
/// <param name="index">Cell index clicked</param>
|
||||
/// <param name="toSelected">Whether cell was selected or unselected</param>
|
||||
private void OnCellClick(int index, bool toSelected)
|
||||
{
|
||||
if (toSelected && index != SelectedOptionIndex)
|
||||
{
|
||||
SelectOption(index);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// A method for obtaining the index of a dropdown option string.
|
||||
/// </summary>
|
||||
/// <param name="option">Accepts an option text string that matches a loaded text option.</param>
|
||||
/// <returns>Returns the index of the provided option string</returns>
|
||||
public int GetOptionIndex(string option)
|
||||
{
|
||||
if (_options != null)
|
||||
{
|
||||
for (int o = 0; o < _options.Length; o++)
|
||||
{
|
||||
if (string.Equals(_options[o], option))
|
||||
{
|
||||
return o;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region APPEARANCE
|
||||
/// <summary>
|
||||
/// Show or hide the popup
|
||||
/// </summary>
|
||||
/// <param name="toShowing">The option index to be selected</param>
|
||||
public void SetShowing(bool toShowing)
|
||||
{
|
||||
if (toShowing && (Options == null || Options.Length <= 0))
|
||||
{
|
||||
Debug.Log("SimpleDropdownList - Cannot show without any options");
|
||||
return;
|
||||
}
|
||||
IsShowing = toShowing;
|
||||
_dropdownToggle.isOn = IsShowing;
|
||||
if (_dropdownListPopup != null)
|
||||
{
|
||||
_dropdownListPopup.alpha = toShowing ? 1f : 0f;
|
||||
_dropdownListPopup.interactable = toShowing;
|
||||
_dropdownListPopup.blocksRaycasts = toShowing;
|
||||
}
|
||||
if (_dropdownButtonArrowImage != null)
|
||||
{
|
||||
_dropdownButtonArrowImage.localRotation = Quaternion.Euler(0f, 0f, IsShowing ? 0f : 180f);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Called when toggle button is clicked
|
||||
/// </summary>
|
||||
private void OnToggleClick(bool toToggle)
|
||||
{
|
||||
if (toToggle != IsShowing)
|
||||
{
|
||||
SetShowing(toToggle);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d02d4f2f4a56a5c4bb1f95bc6a8f3a0c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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;
|
||||
using Meta.WitAi.TTS.Data;
|
||||
using Meta.WitAi.TTS.Integrations;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Meta.Voice.Samples.TTSVoices
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0bb771ba1b3db6649a2bd0b5a31a37c9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
namespace Meta.Voice.Samples.TTSVoices
|
||||
{
|
||||
public class TTSErrorText : MonoBehaviour
|
||||
{
|
||||
// Label
|
||||
[SerializeField] private Text _errorLabel;
|
||||
|
||||
// Current error response
|
||||
private string _error;
|
||||
|
||||
// Reset on enable
|
||||
private void OnEnable()
|
||||
{
|
||||
RefreshText();
|
||||
}
|
||||
|
||||
// Add listeners
|
||||
private void Update()
|
||||
{
|
||||
string invalidError = TTSService.Instance == null ? "No TTS Service Found" : TTSService.Instance.GetInvalidError();
|
||||
if (!string.Equals(invalidError, _error))
|
||||
{
|
||||
_error = invalidError;
|
||||
RefreshText();
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh text
|
||||
private void RefreshText()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_error))
|
||||
{
|
||||
_errorLabel.text = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorLabel.text = $"Error: {_error}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 068bc7513e88e664c817d3597ab8e589
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -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 System;
|
||||
using System.Collections.Generic;
|
||||
using Meta.WitAi.Requests;
|
||||
using Meta.WitAi.TTS;
|
||||
using Meta.WitAi.TTS.Data;
|
||||
using Meta.WitAi.TTS.Integrations;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Meta.Voice.Samples.TTSVoices
|
||||
{
|
||||
public class TTSFileToggle : MonoBehaviour
|
||||
{
|
||||
// UI references
|
||||
[SerializeField] private TTSWit _service;
|
||||
[SerializeField] private Button _button;
|
||||
[SerializeField] private Text _label;
|
||||
[SerializeField] private string _labelFormat = "File Type: {0}";
|
||||
|
||||
// Current audio file type
|
||||
private TTSWitAudioType _fileType = (TTSWitAudioType) (-1);
|
||||
private List<TTSWitAudioType> _fileTypes = new List<TTSWitAudioType>(Enum.GetValues(typeof(TTSWitAudioType)) as TTSWitAudioType[]);
|
||||
|
||||
// Add listeners
|
||||
private void OnEnable()
|
||||
{
|
||||
if (_service == null)
|
||||
{
|
||||
_service = GameObject.FindObjectOfType<TTSWit>();
|
||||
}
|
||||
_button.onClick.AddListener(Toggle);
|
||||
}
|
||||
// Check for changes
|
||||
private void Update()
|
||||
{
|
||||
if (_fileType != _service.RequestSettings.audioType)
|
||||
{
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
// Remove listeners
|
||||
private void OnDisable()
|
||||
{
|
||||
_button.onClick.RemoveListener(Toggle);
|
||||
}
|
||||
|
||||
// Toggle cache
|
||||
private void Toggle()
|
||||
{
|
||||
// Increment to next
|
||||
int index = _fileTypes.IndexOf(_fileType);
|
||||
index++;
|
||||
if (index >= _fileTypes.Count)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
|
||||
// Apply file type
|
||||
_service.RequestSettings.audioType = _fileTypes[index];
|
||||
|
||||
// Clear runtime cache
|
||||
_service.UnloadAll();
|
||||
|
||||
// Refresh
|
||||
Refresh();
|
||||
}
|
||||
|
||||
// Refresh location & button text
|
||||
private void Refresh()
|
||||
{
|
||||
_fileType = _service.RequestSettings.audioType;
|
||||
_label.text = string.Format(_labelFormat, _fileType.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1477d39e8c825744295e2e122d84ca82
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,150 @@
|
||||
/*
|
||||
* 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 UnityEngine;
|
||||
using Meta.WitAi;
|
||||
|
||||
namespace Meta.Voice.Samples.TTSVoices
|
||||
{
|
||||
/// <summary>
|
||||
/// A demo script that uses two dropdown menus to adjust the
|
||||
/// SSML tags of a TTSSpeaker.
|
||||
/// </summary>
|
||||
public class TTSSpeakerEffectSelect : TTSSpeakerObserver
|
||||
{
|
||||
[Header("Effect Settings")]
|
||||
[SerializeField] [Tooltip("Dropdown used for character selection")]
|
||||
private SimpleDropdownList _characterDropdown;
|
||||
[SerializeField] [Tooltip("Dropdown used for environment selection")]
|
||||
private SimpleDropdownList _environmentDropdown;
|
||||
|
||||
// Supported IDs
|
||||
private const string NONE_ID = "NONE";
|
||||
private static readonly string[] CHARACTER_IDS = new [] {NONE_ID, "CHIPMUNK", "MONSTER", "ROBOT", "DAEMON"};
|
||||
private static readonly string[] ENVIRONMENT_IDS = new [] {NONE_ID, "REVERB", "ROOM", "PHONE", "PA", "CATHEDRAL"};
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
RefreshDropdowns();
|
||||
_characterDropdown.OnIndexSelected.AddListener(OnCharacterSelected);
|
||||
_environmentDropdown.OnIndexSelected.AddListener(OnEnvironmentSelected);
|
||||
}
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
_characterDropdown.OnIndexSelected.RemoveListener(OnCharacterSelected);
|
||||
_environmentDropdown.OnIndexSelected.RemoveListener(OnEnvironmentSelected);
|
||||
}
|
||||
|
||||
// Refresh dropdown using voice settings
|
||||
private void RefreshDropdowns()
|
||||
{
|
||||
if (!Speaker)
|
||||
{
|
||||
VLog.W("No speaker found");
|
||||
return;
|
||||
}
|
||||
|
||||
// Refresh characters
|
||||
RefreshDropdown("character", _characterDropdown, CHARACTER_IDS);
|
||||
|
||||
// Refresh environments
|
||||
RefreshDropdown("environments", _environmentDropdown, ENVIRONMENT_IDS);
|
||||
}
|
||||
// Refresh a specific dropdown
|
||||
private void RefreshDropdown(string id, SimpleDropdownList dropdown, string[] options)
|
||||
{
|
||||
if (!dropdown)
|
||||
{
|
||||
VLog.W($"No {id} dropdown found");
|
||||
return;
|
||||
}
|
||||
if (options == null || options.Length == 0)
|
||||
{
|
||||
VLog.W($"No {id} options found");
|
||||
return;
|
||||
}
|
||||
|
||||
// Load dropdown & select first index
|
||||
dropdown.LoadDropdown(options);
|
||||
dropdown.SelectOption(0);
|
||||
}
|
||||
|
||||
// Apply voice on option select
|
||||
private void OnCharacterSelected(int newIndex)
|
||||
{
|
||||
RefreshSsml();
|
||||
}
|
||||
|
||||
// Apply voice on option select
|
||||
private void OnEnvironmentSelected(int newIndex)
|
||||
{
|
||||
RefreshSsml();
|
||||
}
|
||||
|
||||
// Refresh speaker ssml
|
||||
private void RefreshSsml()
|
||||
{
|
||||
if (!Speaker)
|
||||
{
|
||||
VLog.W("No speaker found");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get SSMLs
|
||||
StringBuilder prepend = new StringBuilder();
|
||||
StringBuilder append = new StringBuilder();
|
||||
|
||||
// Add ssml tags
|
||||
prepend.Append("<speak>");
|
||||
append.Append("</speak>");
|
||||
|
||||
// Get character & environment ids
|
||||
string characterId = _characterDropdown.SelectedOption;
|
||||
if (string.Equals(characterId, NONE_ID))
|
||||
{
|
||||
characterId = null;
|
||||
}
|
||||
string environmentId = _environmentDropdown.SelectedOption;
|
||||
if (string.Equals(environmentId, NONE_ID))
|
||||
{
|
||||
environmentId = null;
|
||||
}
|
||||
|
||||
// Add sfx tag
|
||||
bool hasCharacter = !string.IsNullOrEmpty(characterId);
|
||||
bool hasEnvironment = !string.IsNullOrEmpty(environmentId);
|
||||
if (hasCharacter || hasEnvironment)
|
||||
{
|
||||
// Add prefix & postfix
|
||||
prepend.Append("<sfx");
|
||||
append.Insert(0, "</sfx>");
|
||||
|
||||
// Add character
|
||||
if (hasCharacter)
|
||||
{
|
||||
prepend.Append($" character=\"{characterId.ToLower()}\"");
|
||||
}
|
||||
// Add environment
|
||||
if (hasEnvironment)
|
||||
{
|
||||
prepend.Append($" environment=\"{environmentId.ToLower()}\"");
|
||||
}
|
||||
|
||||
// Finalize
|
||||
prepend.Append(">");
|
||||
}
|
||||
|
||||
// Set SSML
|
||||
Speaker.PrependedText = prepend.ToString();
|
||||
Speaker.AppendedText = append.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6048a14add38e0449b1e683cd42a6958
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
175
Assets/Oculus/Voice/Samples/TTSVoices/Scripts/TTSSpeakerInput.cs
Normal file
175
Assets/Oculus/Voice/Samples/TTSVoices/Scripts/TTSSpeakerInput.cs
Normal file
@ -0,0 +1,175 @@
|
||||
/*
|
||||
* 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 System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Meta.WitAi.TTS.Utilities;
|
||||
|
||||
namespace Meta.Voice.Samples.TTSVoices
|
||||
{
|
||||
public class TTSSpeakerInput : MonoBehaviour
|
||||
{
|
||||
// Speaker
|
||||
[SerializeField] private TTSSpeaker _speaker;
|
||||
|
||||
// Default input
|
||||
[SerializeField] private InputField _input;
|
||||
[SerializeField] private Button _stopButton;
|
||||
[SerializeField] private Button _pauseButton;
|
||||
[SerializeField] private Button _speakButton;
|
||||
|
||||
// Queue button that will not stop previous clip
|
||||
[SerializeField] private Toggle _queueButton;
|
||||
// Async toggle that will play a clip on completion
|
||||
[SerializeField] private Toggle _asyncToggle;
|
||||
[SerializeField] private AudioClip _asyncClip;
|
||||
|
||||
[SerializeField] private string _dateId = "[DATE]";
|
||||
[SerializeField] private string[] _queuedText;
|
||||
|
||||
// States
|
||||
private string _voice;
|
||||
private bool _loading;
|
||||
private bool _speaking;
|
||||
private bool _paused;
|
||||
|
||||
// Add delegates
|
||||
private void OnEnable()
|
||||
{
|
||||
RefreshStopButton();
|
||||
RefreshPauseButton();
|
||||
_stopButton.onClick.AddListener(StopClick);
|
||||
_pauseButton.onClick.AddListener(PauseClick);
|
||||
_speakButton.onClick.AddListener(SpeakClick);
|
||||
}
|
||||
// Stop click
|
||||
private void StopClick() => _speaker.Stop();
|
||||
// Pause click
|
||||
private void PauseClick()
|
||||
{
|
||||
if (_speaker.IsPaused)
|
||||
{
|
||||
_speaker.Resume();
|
||||
}
|
||||
else
|
||||
{
|
||||
_speaker.Pause();
|
||||
}
|
||||
}
|
||||
// Speak phrase click
|
||||
private void SpeakClick()
|
||||
{
|
||||
// Speak phrase
|
||||
string phrase = FormatText(_input.text);
|
||||
bool queued = _queueButton != null && _queueButton.isOn;
|
||||
bool async = _asyncToggle != null && _asyncToggle.isOn;
|
||||
|
||||
// Speak async
|
||||
if (async)
|
||||
{
|
||||
StartCoroutine(SpeakAsync(phrase, queued));
|
||||
}
|
||||
// Speak queued
|
||||
else if (queued)
|
||||
{
|
||||
_speaker.SpeakQueued(phrase);
|
||||
}
|
||||
// Speak
|
||||
else
|
||||
{
|
||||
_speaker.Speak(phrase);
|
||||
}
|
||||
|
||||
// Queue additional phrases
|
||||
if (_queuedText != null && _queuedText.Length > 0 && queued)
|
||||
{
|
||||
foreach (var text in _queuedText)
|
||||
{
|
||||
_speaker.SpeakQueued(FormatText(text));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Speak async
|
||||
private IEnumerator SpeakAsync(string phrase, bool queued)
|
||||
{
|
||||
// Queue
|
||||
if (queued)
|
||||
{
|
||||
yield return _speaker.SpeakQueuedAsync(new string[] { phrase });
|
||||
}
|
||||
// Default
|
||||
else
|
||||
{
|
||||
yield return _speaker.SpeakAsync(phrase);
|
||||
}
|
||||
|
||||
// Play complete clip
|
||||
if (_asyncClip != null)
|
||||
{
|
||||
_speaker.AudioSource.PlayOneShot(_asyncClip);
|
||||
}
|
||||
}
|
||||
// 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.ToLongTimeString()}";
|
||||
result = text.Replace(_dateId, dateString);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// Remove delegates
|
||||
private void OnDisable()
|
||||
{
|
||||
_stopButton.onClick.RemoveListener(StopClick);
|
||||
_speakButton.onClick.RemoveListener(SpeakClick);
|
||||
}
|
||||
|
||||
// Preset text fields
|
||||
private void Update()
|
||||
{
|
||||
// On preset voice id update
|
||||
if (!string.Equals(_voice, _speaker.presetVoiceID))
|
||||
{
|
||||
_voice = _speaker.presetVoiceID;
|
||||
_input.placeholder.GetComponent<Text>().text = $"Write something to say in {_voice}'s voice";
|
||||
}
|
||||
// On state changes
|
||||
if (_loading != _speaker.IsLoading)
|
||||
{
|
||||
RefreshStopButton();
|
||||
}
|
||||
if (_speaking != _speaker.IsSpeaking)
|
||||
{
|
||||
RefreshStopButton();
|
||||
}
|
||||
if (_paused != _speaker.IsPaused)
|
||||
{
|
||||
RefreshPauseButton();
|
||||
}
|
||||
}
|
||||
// Refresh interactable based on states
|
||||
private void RefreshStopButton()
|
||||
{
|
||||
_loading = _speaker.IsLoading;
|
||||
_speaking = _speaker.IsSpeaking;
|
||||
_stopButton.interactable = _loading || _speaking;
|
||||
}
|
||||
// Refresh text based on pause state
|
||||
private void RefreshPauseButton()
|
||||
{
|
||||
_paused = _speaker.IsPaused;
|
||||
_pauseButton.GetComponentInChildren<Text>().text = _paused ? "Resume" : "Pause";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2a2f88982fbc6f41a28fbeeb848c631
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,152 @@
|
||||
/*
|
||||
* 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 Meta.WitAi.TTS.Data;
|
||||
using Meta.WitAi.TTS.Utilities;
|
||||
|
||||
namespace Meta.Voice.Samples.TTSVoices
|
||||
{
|
||||
/// <summary>
|
||||
/// A demo script that provides access to a TTSSpeaker
|
||||
/// and overrides all TTSSpeaker callback events.
|
||||
/// </summary>
|
||||
public class TTSSpeakerObserver : MonoBehaviour
|
||||
{
|
||||
[Header("Speaker Settings")]
|
||||
[SerializeField] [Tooltip("TTSSpeaker being observed, if left empty it will grab the speaker from the GameObject")]
|
||||
private TTSSpeaker _speaker;
|
||||
public TTSSpeaker Speaker => _speaker;
|
||||
|
||||
/// <summary>
|
||||
/// Obtains speaker if not set
|
||||
/// </summary>
|
||||
protected virtual void Awake()
|
||||
{
|
||||
if (_speaker == null)
|
||||
{
|
||||
_speaker = gameObject.GetComponentInChildren<TTSSpeaker>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On enable, add all callbacks
|
||||
/// </summary>
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
if (_speaker == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_speaker.Events.OnPlaybackQueueBegin.AddListener(OnPlaybackQueueBegin);
|
||||
_speaker.Events.OnPlaybackQueueComplete.AddListener(OnPlaybackQueueComplete);
|
||||
_speaker.Events.OnLoadBegin.AddListener(OnLoadBegin);
|
||||
_speaker.Events.OnLoadAbort.AddListener(OnLoadAbort);
|
||||
_speaker.Events.OnLoadFailed.AddListener(OnLoadFailed);
|
||||
_speaker.Events.OnLoadSuccess.AddListener(OnLoadSuccess);
|
||||
_speaker.Events.OnPlaybackReady.AddListener(OnPlaybackReady);
|
||||
_speaker.Events.OnPlaybackStart.AddListener(OnPlaybackStart);
|
||||
_speaker.Events.OnPlaybackCancelled.AddListener(OnPlaybackCancelled);
|
||||
_speaker.Events.OnPlaybackComplete.AddListener(OnPlaybackComplete);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On disable, remove all callbacks
|
||||
/// </summary>
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
if (_speaker == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_speaker.Events.OnPlaybackQueueBegin.RemoveListener(OnPlaybackQueueBegin);
|
||||
_speaker.Events.OnPlaybackQueueComplete.RemoveListener(OnPlaybackQueueComplete);
|
||||
_speaker.Events.OnLoadBegin.RemoveListener(OnLoadBegin);
|
||||
_speaker.Events.OnLoadAbort.RemoveListener(OnLoadAbort);
|
||||
_speaker.Events.OnLoadFailed.RemoveListener(OnLoadFailed);
|
||||
_speaker.Events.OnLoadSuccess.RemoveListener(OnLoadSuccess);
|
||||
_speaker.Events.OnPlaybackReady.RemoveListener(OnPlaybackReady);
|
||||
_speaker.Events.OnPlaybackStart.RemoveListener(OnPlaybackStart);
|
||||
_speaker.Events.OnPlaybackCancelled.RemoveListener(OnPlaybackCancelled);
|
||||
_speaker.Events.OnPlaybackComplete.RemoveListener(OnPlaybackComplete);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Callback for queue begin
|
||||
/// </summary>
|
||||
protected virtual void OnPlaybackQueueBegin()
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Callback for queue completion
|
||||
/// </summary>
|
||||
protected virtual void OnPlaybackQueueComplete()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Callback for load begin
|
||||
/// </summary>
|
||||
protected virtual void OnLoadBegin(TTSSpeaker speaker, TTSClipData clipData)
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Callback for load cancelation
|
||||
/// </summary>
|
||||
protected virtual void OnLoadAbort(TTSSpeaker speaker, TTSClipData clipData)
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Callback for load error
|
||||
/// </summary>
|
||||
protected virtual void OnLoadFailed(TTSSpeaker speaker, TTSClipData clipData, string error)
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Callback for load success
|
||||
/// </summary>
|
||||
protected virtual void OnLoadSuccess(TTSSpeaker speaker, TTSClipData clipData)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Callback for playback is ready for a clip
|
||||
/// </summary>
|
||||
protected virtual void OnPlaybackReady(TTSSpeaker speaker, TTSClipData clipData)
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Callback for playback for a clip has begun
|
||||
/// </summary>
|
||||
protected virtual void OnPlaybackStart(TTSSpeaker speaker, TTSClipData clipData)
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Callback for playback for a clip has been canceled
|
||||
/// </summary>
|
||||
protected virtual void OnPlaybackCancelled(TTSSpeaker speaker, TTSClipData clipData, string reason)
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Callback for playback completion
|
||||
/// </summary>
|
||||
protected virtual void OnPlaybackComplete(TTSSpeaker speaker, TTSClipData clipData)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04b4aa12d54b5eb41b8666111dbe7e71
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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 UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Meta.WitAi.TTS.Data;
|
||||
using Meta.WitAi.TTS.Utilities;
|
||||
|
||||
namespace Meta.Voice.Samples.TTSVoices
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple script for providing clip information to a Text label
|
||||
/// </summary>
|
||||
public class TTSSpeakerStatusLabel : TTSSpeakerObserver
|
||||
{
|
||||
[SerializeField] private Text _label;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
RefreshLabel();
|
||||
}
|
||||
protected override void OnLoadBegin(TTSSpeaker speaker, TTSClipData clipData)
|
||||
{
|
||||
RefreshLabel();
|
||||
}
|
||||
protected override void OnLoadAbort(TTSSpeaker speaker, TTSClipData clipData)
|
||||
{
|
||||
RefreshLabel();
|
||||
}
|
||||
protected override void OnLoadFailed(TTSSpeaker speaker, TTSClipData clipData, string error)
|
||||
{
|
||||
RefreshLabel();
|
||||
}
|
||||
protected override void OnLoadSuccess(TTSSpeaker speaker, TTSClipData clipData)
|
||||
{
|
||||
RefreshLabel();
|
||||
}
|
||||
protected override void OnPlaybackReady(TTSSpeaker speaker, TTSClipData clipData)
|
||||
{
|
||||
RefreshLabel();
|
||||
}
|
||||
protected override void OnPlaybackStart(TTSSpeaker speaker, TTSClipData clipData)
|
||||
{
|
||||
RefreshLabel();
|
||||
}
|
||||
protected override void OnPlaybackCancelled(TTSSpeaker speaker, TTSClipData clipData, string reason)
|
||||
{
|
||||
RefreshLabel();
|
||||
}
|
||||
protected override void OnPlaybackComplete(TTSSpeaker speaker, TTSClipData clipData)
|
||||
{
|
||||
RefreshLabel();
|
||||
}
|
||||
private void RefreshLabel()
|
||||
{
|
||||
StringBuilder status = new StringBuilder();
|
||||
int count = 1;
|
||||
if (Speaker.IsSpeaking)
|
||||
{
|
||||
status.Append($"Speaking[{count}]: '{Speaker.SpeakingClip.textToSpeak}'");
|
||||
status.AppendLine("\n");
|
||||
count++;
|
||||
}
|
||||
foreach (var clip in Speaker.QueuedClips)
|
||||
{
|
||||
status.Append($"{clip.loadState.ToString()}[{count}]: '{clip.textToSpeak}'");
|
||||
status.AppendLine("\n");
|
||||
count++;
|
||||
}
|
||||
_label.text = status.ToString();
|
||||
_label.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _label.preferredHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57fe967670cb74c419e8588c173b0583
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.Linq;
|
||||
using UnityEngine;
|
||||
using Meta.WitAi;
|
||||
|
||||
namespace Meta.Voice.Samples.TTSVoices
|
||||
{
|
||||
/// <summary>
|
||||
/// A demo script that uses a dropdown menu to adjust the
|
||||
/// voice setting id of a TTSSpeaker.
|
||||
/// </summary>
|
||||
public class TTSSpeakerVoiceSelect : TTSSpeakerObserver
|
||||
{
|
||||
[SerializeField] [Tooltip("Dropdown used for voice selection")]
|
||||
private SimpleDropdownList _dropdown;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
_dropdown.DropdownToggleUnselectedText = "CUSTOM";
|
||||
}
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
RefreshDropdown();
|
||||
_dropdown.OnOptionSelected.AddListener(OnOptionSelected);
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
_dropdown.OnOptionSelected.RemoveListener(OnOptionSelected);
|
||||
}
|
||||
|
||||
// Fix voice selection if changed elsewhere
|
||||
private void Update()
|
||||
{
|
||||
if (!string.Equals(Speaker?.VoiceSettings?.SettingsId, _dropdown.SelectedOption))
|
||||
{
|
||||
_dropdown.SelectOption(Speaker?.VoiceSettings?.SettingsId);
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh dropdown using voice settings
|
||||
private void RefreshDropdown()
|
||||
{
|
||||
if (!Speaker)
|
||||
{
|
||||
VLog.W("No speaker found");
|
||||
return;
|
||||
}
|
||||
if (!Speaker.TTSService)
|
||||
{
|
||||
VLog.W("No speaker service found");
|
||||
return;
|
||||
}
|
||||
if (!_dropdown)
|
||||
{
|
||||
VLog.W("No dropdown found");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get all voice names & load dropdown
|
||||
string[] voiceNames = Speaker.TTSService.GetAllPresetVoiceSettings()
|
||||
.Select((voiceSetting) => voiceSetting.SettingsId).ToArray();
|
||||
_dropdown.LoadDropdown(voiceNames);
|
||||
|
||||
// Get selected voice &
|
||||
_dropdown.SelectOption(Speaker.presetVoiceID);
|
||||
}
|
||||
|
||||
// Apply voice on option select
|
||||
private void OnOptionSelected(string newOption)
|
||||
{
|
||||
if (!Speaker)
|
||||
{
|
||||
VLog.W("No speaker found");
|
||||
return;
|
||||
}
|
||||
Speaker.presetVoiceID = newOption;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34daf0baa6f344a4f9256495171ccec0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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;
|
||||
_service.UnloadAll();
|
||||
}
|
||||
}
|
||||
// Update if changed externally
|
||||
private void Update()
|
||||
{
|
||||
if (_streamEnabled != GetStreaming())
|
||||
{
|
||||
RefreshStreaming();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c780cd978be73ed43909c99f5fbcee4e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
11
Assets/Oculus/Voice/Samples/TTSVoices/Scripts/phrases.txt
Normal file
11
Assets/Oculus/Voice/Samples/TTSVoices/Scripts/phrases.txt
Normal 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.
|
||||
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7bc5942879ad5394b88ffcc2db2f52f3
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Oculus/Voice/Samples/TTSVoices/TTS Voices - WitConfiguration.asset
(Stored with Git LFS)
Normal file
BIN
Assets/Oculus/Voice/Samples/TTSVoices/TTS Voices - WitConfiguration.asset
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6329e25e1005d4845b580a523e588979
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Oculus/Voice/Samples/TTSVoices/TTSVoices.unity
(Stored with Git LFS)
Normal file
BIN
Assets/Oculus/Voice/Samples/TTSVoices/TTSVoices.unity
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e99baad8337e84a4f93e76c76b8ce49b
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user