Initialer Upload neues Unity-Projekt
This commit is contained in:
8
Assets/Oculus/Voice/Scripts/Editor.meta
Normal file
8
Assets/Oculus/Voice/Scripts/Editor.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c9058da2dd553e4e8cc1a664ea5bc0d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Oculus/Voice/Scripts/Editor/Data.meta
Normal file
8
Assets/Oculus/Voice/Scripts/Editor/Data.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9b850b590def934d88d46d5f230177b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using Meta.WitAi;
|
||||
using Meta.WitAi.Configuration;
|
||||
using Meta.WitAi.Data;
|
||||
using Meta.WitAi.Data.Configuration;
|
||||
using Meta.WitAi.Windows;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Voice.Data
|
||||
{
|
||||
[Serializable]
|
||||
public class VoiceSDKDataCreation
|
||||
{
|
||||
[MenuItem("Assets/Create/Voice SDK/Add App Voice Experience to Scene", false, 100)]
|
||||
public static void AddVoiceCommandServiceToScene()
|
||||
{
|
||||
var witGo = new GameObject();
|
||||
witGo.name = "App Voice Experience";
|
||||
var wit = witGo.AddComponent<AppVoiceExperience>();
|
||||
wit.RuntimeConfiguration = new WitRuntimeConfiguration
|
||||
{
|
||||
witConfiguration = WitDataCreation.FindDefaultWitConfig()
|
||||
};
|
||||
}
|
||||
|
||||
[MenuItem("Assets/Create/Voice SDK/Values/String Value")]
|
||||
public static void WitStringValue()
|
||||
{
|
||||
WitDataCreation.CreateStringValue("");
|
||||
}
|
||||
|
||||
[MenuItem("Assets/Create/Voice SDK/Values/Float Value")]
|
||||
public static void WitFloatValue()
|
||||
{
|
||||
WitDataCreation.CreateFloatValue("");
|
||||
}
|
||||
|
||||
[MenuItem("Assets/Create/Voice SDK/Values/Int Value")]
|
||||
public static void WitIntValue()
|
||||
{
|
||||
WitDataCreation.CreateIntValue("");
|
||||
}
|
||||
|
||||
[MenuItem("Assets/Create/Voice SDK/Configuration", false, 200)]
|
||||
public static void CreateWitConfiguration()
|
||||
{
|
||||
WitWindowUtility.OpenSetupWindow(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 766b749f675dba94a92bb81ebf699d06
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
3
Assets/Oculus/Voice/Scripts/Editor/Hub.meta
Normal file
3
Assets/Oculus/Voice/Scripts/Editor/Hub.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5aef3e0e14d24405919aea5fa6551f92
|
||||
timeCreated: 1681334037
|
||||
30
Assets/Oculus/Voice/Scripts/Editor/Hub/VoiceSettings.cs
Normal file
30
Assets/Oculus/Voice/Scripts/Editor/Hub/VoiceSettings.cs
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.Voice.Hub.Attributes;
|
||||
using Meta.Voice.Hub.Interfaces;
|
||||
using Meta.Voice.VSDKHub;
|
||||
using Meta.Voice.Windows;
|
||||
using Oculus.Voice.Utility;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Meta.Voice.Hub
|
||||
{
|
||||
[MetaHubPage("Settings", VoiceHubConstants.CONTEXT_VOICE, priority: 800)]
|
||||
public class SettingsWindowPage : SettingsWindow, IMetaHubPage
|
||||
{
|
||||
protected override GUIContent Title => new GUIContent("Voice SDK Settings");
|
||||
protected override Texture2D HeaderIcon => null;
|
||||
protected override string DocsUrl => VoiceSDKStyles.Texts.VoiceDocsUrl;
|
||||
|
||||
public new void OnGUI()
|
||||
{
|
||||
base.OnGUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f28381e065624802b1cf1a6a2c98c644
|
||||
timeCreated: 1681333993
|
||||
8
Assets/Oculus/Voice/Scripts/Editor/Inspectors.meta
Normal file
8
Assets/Oculus/Voice/Scripts/Editor/Inspectors.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e7c523618d37124d82a50597af82815
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Meta.WitAi.Inspectors;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Oculus.Voice.Inspectors
|
||||
{
|
||||
[CustomEditor(typeof(AppVoiceExperience))]
|
||||
public class AppVoiceExperienceEditor : WitInspector
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03744310c46b6e546b2b772e941f8cb2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Meta.WitAi.Data.Configuration;
|
||||
using Meta.WitAi.Windows;
|
||||
using Meta.WitAi;
|
||||
using Meta.WitAi.Data.Info;
|
||||
using Oculus.Voice.Utility;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Voice.Inspectors
|
||||
{
|
||||
[CustomEditor(typeof(WitConfiguration))]
|
||||
public class AppVoiceExperienceWitConfigurationEditor : WitConfigurationEditor
|
||||
{
|
||||
// Override with voice sdk header
|
||||
protected override Texture2D HeaderIcon => VoiceSDKStyles.MainHeader;
|
||||
public override string HeaderUrl => GetSafeAppUrl(Configuration, WitTexts.WitAppEndpointType.Settings);
|
||||
protected override string DocsUrl => VoiceSDKStyles.Texts.VoiceDocsUrl;
|
||||
protected override string OpenButtonLabel => IsBuiltInConfiguration(Configuration) ? VoiceSDKStyles.Texts.BuiltInAppBtnLabel : base.OpenButtonLabel;
|
||||
|
||||
// Disable server functionality for built in configurations
|
||||
protected override bool _disableServerPost => IsBuiltInConfiguration(Configuration);
|
||||
|
||||
// Use to determine if built in configuration
|
||||
public static bool IsBuiltInConfiguration(WitConfiguration witConfiguration)
|
||||
{
|
||||
if (witConfiguration == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return IsBuiltInConfiguration(witConfiguration.GetApplicationInfo());
|
||||
}
|
||||
public static bool IsBuiltInConfiguration(WitAppInfo appInfo)
|
||||
{
|
||||
return IsBuiltInConfiguration(appInfo.id);
|
||||
}
|
||||
public static bool IsBuiltInConfiguration(string applicationID)
|
||||
{
|
||||
return !string.IsNullOrEmpty(applicationID) && applicationID.StartsWith("voice");
|
||||
}
|
||||
|
||||
// Get safe app url
|
||||
public static string GetSafeAppUrl(WitConfiguration witConfiguration, WitTexts.WitAppEndpointType endpointType)
|
||||
{
|
||||
// Use built in app url
|
||||
if (IsBuiltInConfiguration(witConfiguration))
|
||||
{
|
||||
return VoiceSDKStyles.Texts.BuiltInAppUrl;
|
||||
}
|
||||
// Return wit app id
|
||||
return WitTexts.GetAppURL(witConfiguration?.GetApplicationId(), endpointType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81dc8ceb5197487fa6b8f684c40a0a06
|
||||
timeCreated: 1630651402
|
||||
8
Assets/Oculus/Voice/Scripts/Editor/Upgrade.meta
Normal file
8
Assets/Oculus/Voice/Scripts/Editor/Upgrade.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a51109e9358cfd4fa1690bede306b75
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
55
Assets/Oculus/Voice/Scripts/Editor/Upgrade/WitUpgrader.cs
Normal file
55
Assets/Oculus/Voice/Scripts/Editor/Upgrade/WitUpgrader.cs
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Meta.WitAi;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Voice.Upgrade
|
||||
{
|
||||
[CustomEditor(typeof(Wit), false)]
|
||||
public class WitUpgrader : Editor
|
||||
{
|
||||
class Styles
|
||||
{
|
||||
public static GUIContent upgrade = new GUIContent("Upgrade to App Voice Experience",
|
||||
"This will replace your Wit object with a comparable component from the Voice SDK.");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
var wit = (Wit) target;
|
||||
if (!wit.GetComponent<AppVoiceExperience>())
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
|
||||
if (!Application.isPlaying && GUILayout.Button(Styles.upgrade))
|
||||
{
|
||||
var voiceService = wit.gameObject.AddComponent<AppVoiceExperience>();
|
||||
voiceService.VoiceEvents = wit.VoiceEvents;
|
||||
voiceService.RuntimeConfiguration = wit.RuntimeConfiguration;
|
||||
var voiceServiceSerializedObject = new SerializedObject(voiceService);
|
||||
voiceServiceSerializedObject.ApplyModifiedProperties();
|
||||
DestroyImmediate(wit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b6dc5be923e4794fbc03577778257f0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Oculus/Voice/Scripts/Editor/Utility.meta
Normal file
8
Assets/Oculus/Voice/Scripts/Editor/Utility.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c74dbc89a3023bb41b841587da9e9953
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
98
Assets/Oculus/Voice/Scripts/Editor/Utility/VoiceSDKMenu.cs
Normal file
98
Assets/Oculus/Voice/Scripts/Editor/Utility/VoiceSDKMenu.cs
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Meta.Voice.VSDKHub;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Meta.WitAi.Windows;
|
||||
using Meta.WitAi.Data.Entities;
|
||||
using Meta.WitAi.TTS;
|
||||
using Meta.WitAi.TTS.Preload;
|
||||
|
||||
namespace Oculus.Voice.Utility
|
||||
{
|
||||
public static class VoiceSDKMenu
|
||||
{
|
||||
#region WINDOWS
|
||||
[MenuItem("Oculus/Voice SDK/Get Started", false, 1)]
|
||||
private static void OpenConfigurationWindow()
|
||||
{
|
||||
WitWindowUtility.OpenGettingStarted((config) =>
|
||||
{
|
||||
VoiceSDKHub.ShowPage(VoiceSDKHub.GetPageId(VoiceHubConstants.PAGE_WIT_CONFIGS));
|
||||
});
|
||||
}
|
||||
[MenuItem("Oculus/Voice SDK/Understanding Viewer", false, 200)]
|
||||
private static void OpenUnderstandingWindow()
|
||||
{
|
||||
WitWindowUtility.OpenUnderstandingWindow();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Scriptable Objects
|
||||
[MenuItem("Assets/Create/Voice SDK/Dynamic Entities")]
|
||||
public static void CreateDynamicEntities()
|
||||
{
|
||||
WitDynamicEntitiesData asset =
|
||||
ScriptableObject.CreateInstance<WitDynamicEntitiesData>();
|
||||
|
||||
var path = EditorUtility.SaveFilePanel("Save Dynamic Entity", Application.dataPath,
|
||||
"DynamicEntities", "asset");
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
path = "Assets/" + path.Replace(Application.dataPath, "");
|
||||
AssetDatabase.CreateAsset(asset, path);
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
EditorUtility.FocusProjectWindow();
|
||||
|
||||
Selection.activeObject = asset;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TTS
|
||||
|
||||
[MenuItem("Assets/Create/Voice SDK/TTS/Add Default TTS Setup")]
|
||||
public static void CreateDefaultTTSSetup()
|
||||
{
|
||||
TTSEditorUtilities.CreateDefaultSetup();
|
||||
}
|
||||
|
||||
[MenuItem("Assets/Create/Voice SDK/TTS/Add TTS Service to Scene", false, 100)]
|
||||
public static void CreateTTSService()
|
||||
{
|
||||
TTSEditorUtilities.CreateService();
|
||||
}
|
||||
|
||||
[MenuItem("Assets/Create/Voice SDK/TTS/Add TTS Speaker to Scene", false, 100)]
|
||||
public static void CreateTTSSpeaker()
|
||||
{
|
||||
TTSEditorUtilities.CreateSpeaker();
|
||||
}
|
||||
[MenuItem("Assets/Create/Voice SDK/TTS/Preload Settings", false, 200)]
|
||||
public static void CreateTTSPreloadSettings()
|
||||
{
|
||||
TTSPreloadUtility.CreatePreloadSettings();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: edfc5f7f2010aa340af1f2b286930dc6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
82
Assets/Oculus/Voice/Scripts/Editor/Utility/VoiceSDKStyles.cs
Normal file
82
Assets/Oculus/Voice/Scripts/Editor/Utility/VoiceSDKStyles.cs
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Meta.WitAi;
|
||||
|
||||
namespace Oculus.Voice.Utility
|
||||
{
|
||||
public static class VoiceSDKStyles
|
||||
{
|
||||
[Serializable]
|
||||
public struct VoiceSDKTexts
|
||||
{
|
||||
[Header("Setup Texts")]
|
||||
public string SetupTitleLabel;
|
||||
public string SetupHeaderLabel;
|
||||
public string SetupSubheaderLabel;
|
||||
public string SetupLanguageLabel;
|
||||
public string VoiceDocsUrl;
|
||||
[Header("About Texts")]
|
||||
public string AboutTitleLabel;
|
||||
public string AboutCloseLabel;
|
||||
public string AboutVoiceSdkVersionLabel;
|
||||
public string AboutWitSdkVersionLabel;
|
||||
public string AboutWitApiVersionLabel;
|
||||
public string AboutTutorialButtonLabel;
|
||||
public string AboutTutorialButtonUrl;
|
||||
[Header("Settings Texts")]
|
||||
public string SettingsTitleLabel;
|
||||
[Header("Understanding Viewer Texts")]
|
||||
public string UnderstandingViewerTitleLabel;
|
||||
[Header("Built-In Texts")]
|
||||
public string BuiltInAppBtnLabel;
|
||||
public string BuiltInAppUrl;
|
||||
}
|
||||
public static VoiceSDKTexts Texts;
|
||||
|
||||
public static Texture2D MainHeader;
|
||||
public static GUIContent SetupTitle;
|
||||
public static GUIContent AboutTitle;
|
||||
public static GUIContent SettingsTitle;
|
||||
public static GUIContent UnderstandingTitle;
|
||||
|
||||
static VoiceSDKStyles()
|
||||
{
|
||||
// Load localization
|
||||
string languageID = "en-us";
|
||||
string textFilePath = $"voicesdk_texts_{languageID}";
|
||||
TextAsset textAsset = Resources.Load<TextAsset>(textFilePath);
|
||||
if (textAsset == null)
|
||||
{
|
||||
VLog.E($"VoiceSDK Texts - Add localization to Resources/{textFilePath}\nLanguage: {languageID}");
|
||||
return;
|
||||
}
|
||||
Texts = JsonUtility.FromJson<VoiceSDKTexts>(textAsset.text);
|
||||
|
||||
MainHeader = (Texture2D) Resources.Load("voicesdk_heroart");
|
||||
SetupTitle = new GUIContent(Texts.SetupTitleLabel);
|
||||
AboutTitle = new GUIContent(Texts.AboutTitleLabel);
|
||||
SettingsTitle = new GUIContent(Texts.SettingsTitleLabel);
|
||||
UnderstandingTitle = new GUIContent(Texts.UnderstandingViewerTitleLabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa1f0af066e824a31875bc815a72cc5c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using Oculus.VoiceSDK;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Voice.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Obsolete class for editor version info
|
||||
/// </summary>
|
||||
public class VoiceSDKVersion : MonoBehaviour
|
||||
{
|
||||
[Obsolete("Use 'VoiceSDKConstants.SdkVersion' directly")]
|
||||
public static string VERSION => VoiceSDKConstants.SdkVersion;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5bf6b7b99e36e104f964fb70253f847c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
33
Assets/Oculus/Voice/Scripts/Editor/VoiceSDK.Editor.asmdef
Normal file
33
Assets/Oculus/Voice/Scripts/Editor/VoiceSDK.Editor.asmdef
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "VoiceSDK.Editor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:e545cc0678493234a9368f4e470c29e8",
|
||||
"GUID:4504b1a6e0fdcc3498c30b266e4a63bf",
|
||||
"GUID:fa958eb9f0171754fb207d563a15ddfa",
|
||||
"GUID:8bbcefc153e1f1b4a98680670797dd16",
|
||||
"GUID:e31cc0253d8f956459091c800a16d68d",
|
||||
"GUID:1c28d8b71ced07540b7c271537363cc6",
|
||||
"GUID:8e054d88729a3fb4bbe539499f824363",
|
||||
"GUID:fb19304c87f76694ca2d792da1915efe",
|
||||
"GUID:a4f6d7d3afe393a4c8034af2ef0f36a8",
|
||||
"GUID:4c3436cc699cb25459568e9fa95b7fd7"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [
|
||||
{
|
||||
"name": "com.meta.xr.sdk.voice.telemetry",
|
||||
"expression": "",
|
||||
"define": "VSDK_TELEMETRY_AVAILABLE"
|
||||
}
|
||||
],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c313d8e945a7904dbf75897c010ac4d
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Oculus/Voice/Scripts/Editor/Windows.meta
Normal file
8
Assets/Oculus/Voice/Scripts/Editor/Windows.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6882087e17a8bbe4c80cf5a6764e6a6b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
56
Assets/Oculus/Voice/Scripts/Editor/Windows/AboutWindow.cs
Normal file
56
Assets/Oculus/Voice/Scripts/Editor/Windows/AboutWindow.cs
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Meta.Voice.VSDKHub;
|
||||
using Meta.Voice.Hub.Attributes;
|
||||
using Meta.Voice.Hub.Interfaces;
|
||||
using Meta.WitAi;
|
||||
using Oculus.Voice.Utility;
|
||||
using Oculus.Voice;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Meta.Voice
|
||||
{
|
||||
[MetaHubPage("About", VoiceHubConstants.CONTEXT_VOICE, priority: 1000)]
|
||||
public class AboutWindow : IMetaHubPage
|
||||
{
|
||||
private Vector2 _offset;
|
||||
|
||||
public void OnGUI()
|
||||
{
|
||||
Vector2 size;
|
||||
WitEditorUI.LayoutWindow(VoiceSDKStyles.Texts.AboutTitleLabel, null, null, null, OnWindowGUI, ref _offset, out size);
|
||||
}
|
||||
|
||||
private void OnWindowGUI()
|
||||
{
|
||||
WitEditorUI.LayoutKeyLabel(VoiceSDKStyles.Texts.AboutVoiceSdkVersionLabel, VoiceSDKConstants.SdkVersion);
|
||||
WitEditorUI.LayoutKeyLabel(VoiceSDKStyles.Texts.AboutWitSdkVersionLabel, WitConstants.SDK_VERSION);
|
||||
WitEditorUI.LayoutKeyLabel(VoiceSDKStyles.Texts.AboutWitApiVersionLabel, WitConstants.API_VERSION);
|
||||
|
||||
GUILayout.Space(16);
|
||||
|
||||
if (WitEditorUI.LayoutTextButton(VoiceSDKStyles.Texts.AboutTutorialButtonLabel))
|
||||
{
|
||||
Application.OpenURL(VoiceSDKStyles.Texts.AboutTutorialButtonUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b92c30adebae6ba4f93106d6fa6f4b3d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- m_ViewDataDictionary: {instanceID: 0}
|
||||
- header: {fileID: 2800000, guid: 41df4ab8a05595e49b2f2d150e753bf7, type: 3}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
98
Assets/Oculus/Voice/Scripts/Editor/Windows/SettingsWindow.cs
Normal file
98
Assets/Oculus/Voice/Scripts/Editor/Windows/SettingsWindow.cs
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Meta.Voice.Hub.Attributes;
|
||||
using Meta.Voice.Hub.Interfaces;
|
||||
using Meta.Voice.VSDKHub;
|
||||
using Meta.WitAi;
|
||||
using Meta.WitAi.Windows;
|
||||
using Oculus.Voice.Utility;
|
||||
using Oculus.Voice.Windows;
|
||||
using UnityEngine;
|
||||
using Meta.Voice.TelemetryUtilities;
|
||||
|
||||
namespace Meta.Voice.Windows
|
||||
{
|
||||
public class SettingsWindow : WitWindow
|
||||
{
|
||||
protected override GUIContent Title => new GUIContent(VoiceSDKStyles.SettingsTitle.text);
|
||||
protected override Texture2D HeaderIcon => VoiceSDKStyles.MainHeader;
|
||||
protected override string DocsUrl => VoiceSDKStyles.Texts.VoiceDocsUrl;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
WitAuthUtility.tokenValidator = new VoiceSDKTokenValidatorProvider();
|
||||
titleContent = Title;
|
||||
base.OnEnable();
|
||||
}
|
||||
}
|
||||
|
||||
[MetaHubPage("Wit Configurations", VoiceHubConstants.CONTEXT_VOICE, priority: 500)]
|
||||
public class WitConfigWindowPage : SettingsWindow, IMetaHubPage
|
||||
{
|
||||
protected override GUIContent Title => new GUIContent("Wit Configurations");
|
||||
protected override Texture2D HeaderIcon => null;
|
||||
protected override string DocsUrl => VoiceSDKStyles.Texts.VoiceDocsUrl;
|
||||
|
||||
public override bool ShowGeneralSettings => false;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
Telemetry.LogInstantEvent(Telemetry.TelemetryEventId.OpenUi, new Dictionary<Telemetry.AnnotationKey, string>()
|
||||
{
|
||||
{Telemetry.AnnotationKey.PageId, "Configuration Window"}
|
||||
});
|
||||
titleContent = Title;
|
||||
}
|
||||
|
||||
public new void OnGUI()
|
||||
{
|
||||
base.OnGUI();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Title.text;
|
||||
}
|
||||
}
|
||||
|
||||
[MetaHubPage("Settings", VoiceHubConstants.CONTEXT_VOICE, priority: 800)]
|
||||
public class SettingsWindowPage : SettingsWindow, IMetaHubPage
|
||||
{
|
||||
protected override GUIContent Title => new GUIContent("Settings");
|
||||
protected override Texture2D HeaderIcon => null;
|
||||
protected override string DocsUrl => VoiceSDKStyles.Texts.VoiceDocsUrl;
|
||||
|
||||
public override bool ShowWitConfiguration => false;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
titleContent = Title;
|
||||
}
|
||||
|
||||
public new void OnGUI()
|
||||
{
|
||||
base.OnGUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c810bb2a5bea4e4897c121e3264df3d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Meta.Voice.TelemetryUtilities;
|
||||
using Meta.WitAi;
|
||||
using Meta.WitAi.Windows;
|
||||
using UnityEngine;
|
||||
using Oculus.Voice.Utility;
|
||||
using Oculus.Voice.Inspectors;
|
||||
|
||||
namespace Oculus.Voice.Windows
|
||||
{
|
||||
public class UnderstandingViewerWindow : WitUnderstandingViewer
|
||||
{
|
||||
protected override GUIContent Title => VoiceSDKStyles.UnderstandingTitle;
|
||||
protected override Texture2D HeaderIcon => VoiceSDKStyles.MainHeader;
|
||||
protected override string HeaderUrl => AppVoiceExperienceWitConfigurationEditor.GetSafeAppUrl(witConfiguration, WitTexts.WitAppEndpointType.Understanding);
|
||||
protected override string DocsUrl => VoiceSDKStyles.Texts.VoiceDocsUrl;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
Telemetry.LogInstantEvent(Telemetry.TelemetryEventId.OpenUi, new Dictionary<Telemetry.AnnotationKey, string>()
|
||||
{
|
||||
{Telemetry.AnnotationKey.PageId, "Configuration Window"}
|
||||
});
|
||||
base.OnEnable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c86fe355d3472b94bbaa52c686a49ddb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using UnityEditor;
|
||||
using System.Reflection;
|
||||
using Meta.WitAi.Data.Info;
|
||||
using Meta.WitAi.Windows;
|
||||
using Oculus.Voice.Inspectors;
|
||||
|
||||
namespace Oculus.Voice.Windows
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(WitAppInfo))]
|
||||
public class VoiceApplicationDetailProvider : WitApplicationPropertyDrawer
|
||||
{
|
||||
// Skip fields if voice sdk app id
|
||||
protected override bool ShouldLayoutField(SerializedProperty property, FieldInfo subfield)
|
||||
{
|
||||
string appID = GetFieldStringValue(property, "id").ToLower();
|
||||
if (AppVoiceExperienceWitConfigurationEditor.IsBuiltInConfiguration(appID))
|
||||
{
|
||||
switch (subfield.Name)
|
||||
{
|
||||
case "name":
|
||||
case "lang":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return base.ShouldLayoutField(property, subfield);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f885966f75e449f6b3912d20c1b85bf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using UnityEditor;
|
||||
|
||||
namespace Oculus.Voice.Windows
|
||||
{
|
||||
public class VoiceSDKWizardWindow : ScriptableWizard
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e81c43e4b4674634a8e8b4e34733945
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- m_ViewDataDictionary: {instanceID: 0}
|
||||
- header: {fileID: 2800000, guid: 41df4ab8a05595e49b2f2d150e753bf7, type: 3}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
130
Assets/Oculus/Voice/Scripts/Editor/Windows/WelcomeWizard.cs
Normal file
130
Assets/Oculus/Voice/Scripts/Editor/Windows/WelcomeWizard.cs
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Meta.Voice.TelemetryUtilities;
|
||||
using Meta.WitAi;
|
||||
using Meta.WitAi.Data.Configuration;
|
||||
using Meta.WitAi.Windows;
|
||||
using Meta.WitAi.Data.Info;
|
||||
using Oculus.Voice.Utility;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Voice.Windows
|
||||
{
|
||||
public class WelcomeWizard : WitWelcomeWizard
|
||||
{
|
||||
private int witBuiltInIndex;
|
||||
private string[] builtinAppNames;
|
||||
|
||||
protected override Texture2D HeaderIcon => VoiceSDKStyles.MainHeader;
|
||||
protected override GUIContent Title => VoiceSDKStyles.SetupTitle;
|
||||
protected override string ContentHeaderLabel => VoiceSDKStyles.Texts.SetupHeaderLabel;
|
||||
protected override string ContentSubheaderLabel => VoiceSDKStyles.Texts.SetupSubheaderLabel;
|
||||
protected override string DocsUrl => VoiceSDKStyles.Texts.VoiceDocsUrl;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
Telemetry.LogInstantEvent(Telemetry.TelemetryEventId.OpenUi, new Dictionary<Telemetry.AnnotationKey, string>()
|
||||
{
|
||||
{Telemetry.AnnotationKey.PageId, "Getting Started"}
|
||||
});
|
||||
|
||||
WitAuthUtility.tokenValidator = new VoiceSDKTokenValidatorProvider();
|
||||
base.OnEnable();
|
||||
witBuiltInIndex = 0;
|
||||
var names = AppBuiltIns.appNames;
|
||||
builtinAppNames = new string[names.Length + 1];
|
||||
builtinAppNames[0] = "Custom App";
|
||||
for (int i = 0; i < names.Length; i++)
|
||||
{
|
||||
builtinAppNames[i + 1] = names[i];
|
||||
}
|
||||
}
|
||||
|
||||
protected override void LayoutFields()
|
||||
{
|
||||
// Prebuilt language app
|
||||
bool updated = false;
|
||||
WitEditorUI.LayoutLabel(VoiceSDKStyles.Texts.SetupLanguageLabel);
|
||||
WitEditorUI.LayoutPopup("", builtinAppNames, ref witBuiltInIndex, ref updated);
|
||||
if (updated)
|
||||
{
|
||||
if (witBuiltInIndex == 0)
|
||||
{
|
||||
serverToken = WitAuthUtility.ServerToken;
|
||||
}
|
||||
else
|
||||
{
|
||||
serverToken = AppBuiltIns.builtInPrefix + builtinAppNames[witBuiltInIndex];
|
||||
}
|
||||
}
|
||||
|
||||
// Base fields
|
||||
if (witBuiltInIndex == 0)
|
||||
{
|
||||
GUILayout.Space(WitStyles.HeaderPaddingBottom);
|
||||
base.LayoutFields();
|
||||
}
|
||||
}
|
||||
|
||||
// Customize configuration if voice app was selected
|
||||
protected override int CreateConfiguration(string newToken)
|
||||
{
|
||||
// Do base for custom app
|
||||
if (witBuiltInIndex <= 0)
|
||||
{
|
||||
return base.CreateConfiguration(newToken);
|
||||
}
|
||||
|
||||
// Get built in app data
|
||||
string languageName = builtinAppNames[witBuiltInIndex];
|
||||
Dictionary<string, string> appData = AppBuiltIns.apps[languageName];
|
||||
|
||||
// Generate asset using app data
|
||||
WitConfiguration configuration = ScriptableObject.CreateInstance<WitConfiguration>();
|
||||
configuration.SetClientAccessToken(appData["clientToken"]);
|
||||
WitAppInfo application = new WitAppInfo()
|
||||
{
|
||||
name = appData["name"],
|
||||
id = appData["id"],
|
||||
lang = appData["lang"]
|
||||
};
|
||||
configuration.SetApplicationInfo(application);
|
||||
configuration.name = application.id;
|
||||
|
||||
// Save configuration to asset
|
||||
return WitConfigurationUtility.SaveConfiguration(string.Empty, configuration);
|
||||
}
|
||||
}
|
||||
|
||||
public class VoiceSDKTokenValidatorProvider : WitAuthUtility.ITokenValidationProvider
|
||||
{
|
||||
public bool IsTokenValid(string appId, string token)
|
||||
{
|
||||
return IsServerTokenValid(token);
|
||||
}
|
||||
|
||||
public bool IsServerTokenValid(string serverToken)
|
||||
{
|
||||
return null != serverToken && (serverToken.Length == 32 || serverToken.StartsWith(AppBuiltIns.builtInPrefix));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1969028d6c8d24d5c83929e0d846ac21
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- m_ViewDataDictionary: {instanceID: 0}
|
||||
- header: {fileID: 2800000, guid: 41df4ab8a05595e49b2f2d150e753bf7, type: 3}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Oculus/Voice/Scripts/Runtime.meta
Normal file
8
Assets/Oculus/Voice/Scripts/Runtime.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 825cea7c5dd397348af75ce59831a2af
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
3
Assets/Oculus/Voice/Scripts/Runtime/Bindings.meta
Normal file
3
Assets/Oculus/Voice/Scripts/Runtime/Bindings.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bbc4c49e0d6b4e739b6daa5d08e00632
|
||||
timeCreated: 1630370504
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10a5b9b665ad462cb8d1e8d6cde9bc11
|
||||
timeCreated: 1630370518
|
||||
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Oculus.Voice.Bindings.Android
|
||||
{
|
||||
public interface IVCBindingEvents
|
||||
{
|
||||
void OnServiceNotAvailable(string error, string message);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d01044a09129d474caffc360d188bd52
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Meta.WitAi.Configuration;
|
||||
using Oculus.Voice.Core.Bindings.Android;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Voice.Bindings.Android
|
||||
{
|
||||
public class VoiceSDKBinding : BaseServiceBinding
|
||||
{
|
||||
public VoiceSDKBinding(AndroidJavaObject sdkInstance) : base(sdkInstance)
|
||||
{
|
||||
}
|
||||
|
||||
public bool Active => binding.Call<bool>("isActive");
|
||||
public bool IsRequestActive => binding.Call<bool>("isRequestActive");
|
||||
public bool MicActive => binding.Call<bool>("isMicActive");
|
||||
public bool PlatformSupportsWit => binding.Call<bool>("isSupported");
|
||||
|
||||
public void Activate(string text, WitRequestOptions options)
|
||||
{
|
||||
binding.Call("activate", text, options.ToJsonString());
|
||||
}
|
||||
|
||||
public void Activate(WitRequestOptions options)
|
||||
{
|
||||
binding.Call("activate", options.ToJsonString());
|
||||
}
|
||||
|
||||
public void ActivateImmediately(WitRequestOptions options)
|
||||
{
|
||||
binding.Call("activateImmediately", options.ToJsonString());
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
{
|
||||
binding.Call("deactivate");
|
||||
}
|
||||
|
||||
public void DeactivateAndAbortRequest()
|
||||
{
|
||||
binding.Call("deactivateAndAbortRequest");
|
||||
}
|
||||
|
||||
public void SetRuntimeConfiguration(WitRuntimeConfiguration configuration)
|
||||
{
|
||||
binding.Call("setRuntimeConfig", new VoiceSDKConfigBinding(configuration).ToJavaObject());
|
||||
}
|
||||
|
||||
public void SetListener(VoiceSDKListenerBinding listener)
|
||||
{
|
||||
binding.Call("setListener", listener);
|
||||
}
|
||||
|
||||
public void Connect()
|
||||
{
|
||||
binding.Call<bool>("connect");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d8c1d6d5b8545cfb741ca067158491a
|
||||
timeCreated: 1630371197
|
||||
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Meta.WitAi.Configuration;
|
||||
using Meta.WitAi;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Voice.Bindings.Android
|
||||
{
|
||||
public class VoiceSDKConfigBinding
|
||||
{
|
||||
private WitRuntimeConfiguration configuration;
|
||||
|
||||
public VoiceSDKConfigBinding(WitRuntimeConfiguration config)
|
||||
{
|
||||
configuration = config;
|
||||
}
|
||||
|
||||
public AndroidJavaObject ToJavaObject()
|
||||
{
|
||||
AndroidJavaObject witConfig =
|
||||
new AndroidJavaObject("com.oculus.assistant.api.voicesdk.immersivevoicecommands.WitConfiguration");
|
||||
witConfig.Set("clientAccessToken", configuration.witConfiguration.GetClientAccessToken());
|
||||
|
||||
AndroidJavaObject witRuntimeConfig = new AndroidJavaObject("com.oculus.assistant.api.voicesdk.immersivevoicecommands.WitRuntimeConfiguration");
|
||||
witRuntimeConfig.Set("witConfiguration", witConfig);
|
||||
|
||||
witRuntimeConfig.Set("minKeepAliveVolume", configuration.minKeepAliveVolume);
|
||||
witRuntimeConfig.Set("minKeepAliveTimeInSeconds",
|
||||
configuration.minKeepAliveTimeInSeconds);
|
||||
witRuntimeConfig.Set("minTranscriptionKeepAliveTimeInSeconds",
|
||||
configuration.minTranscriptionKeepAliveTimeInSeconds);
|
||||
witRuntimeConfig.Set("maxRecordingTime",
|
||||
configuration.maxRecordingTime);
|
||||
witRuntimeConfig.Set("soundWakeThreshold",
|
||||
configuration.soundWakeThreshold);
|
||||
witRuntimeConfig.Set("sampleLengthInMs",
|
||||
configuration.sampleLengthInMs);
|
||||
witRuntimeConfig.Set("micBufferLengthInSeconds",
|
||||
configuration.micBufferLengthInSeconds);
|
||||
witRuntimeConfig.Set("sendAudioToWit",
|
||||
configuration.sendAudioToWit);
|
||||
witRuntimeConfig.Set("preferredActivationOffset",
|
||||
configuration.preferredActivationOffset);
|
||||
witRuntimeConfig.Set("clientName",
|
||||
WitConstants.CLIENT_NAME);
|
||||
witRuntimeConfig.Set("serverVersion",
|
||||
WitConstants.API_VERSION);
|
||||
|
||||
return witRuntimeConfig;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 114218fd50f24874adaaf0e91a865d75
|
||||
timeCreated: 1630370973
|
||||
@ -0,0 +1,286 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Meta.Voice;
|
||||
using Meta.WitAi;
|
||||
using Meta.WitAi.Configuration;
|
||||
using Meta.WitAi.Events;
|
||||
using Meta.WitAi.Interfaces;
|
||||
using Meta.WitAi.Requests;
|
||||
using Oculus.Voice.Core.Bindings.Android;
|
||||
using Oculus.Voice.Interfaces;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
namespace Oculus.Voice.Bindings.Android
|
||||
{
|
||||
public class VoiceSDKImpl : BaseAndroidConnectionImpl<VoiceSDKBinding>,
|
||||
IPlatformVoiceService, IVCBindingEvents
|
||||
{
|
||||
private bool _isServiceAvailable = true;
|
||||
public Action OnServiceNotAvailableEvent;
|
||||
private IVoiceService _baseVoiceService;
|
||||
|
||||
private bool _isActive;
|
||||
|
||||
public VoiceSDKImpl(IVoiceService baseVoiceService) : base(
|
||||
"com.oculus.assistant.api.unity.immersivevoicecommands.UnityIVCServiceFragment")
|
||||
{
|
||||
_baseVoiceService = baseVoiceService;
|
||||
}
|
||||
|
||||
public bool UsePlatformIntegrations
|
||||
{
|
||||
get => true;
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool PlatformSupportsWit => service.PlatformSupportsWit && _isServiceAvailable;
|
||||
|
||||
public bool Active => service.Active && _isActive;
|
||||
public bool IsRequestActive => service.IsRequestActive;
|
||||
public bool MicActive => service.MicActive;
|
||||
public void SetRuntimeConfiguration(WitRuntimeConfiguration configuration)
|
||||
{
|
||||
service.SetRuntimeConfiguration(configuration);
|
||||
}
|
||||
|
||||
private VoiceSDKListenerBinding eventBinding;
|
||||
|
||||
public HashSet<VoiceServiceRequest> Requests { get; } = new HashSet<VoiceServiceRequest>();
|
||||
|
||||
public ITranscriptionProvider TranscriptionProvider { get; set; }
|
||||
public bool CanActivateAudio()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanSend()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Connect(string version)
|
||||
{
|
||||
base.Connect(version);
|
||||
eventBinding = new VoiceSDKListenerBinding(this, this);
|
||||
eventBinding.VoiceEvents.OnStoppedListening.AddListener(OnStoppedListening);
|
||||
service.SetListener(eventBinding);
|
||||
service.Connect();
|
||||
Debug.Log(
|
||||
$"Platform integration initialization complete. Platform integrations are {(PlatformSupportsWit ? "active" : "inactive")}");
|
||||
}
|
||||
|
||||
public override void Disconnect()
|
||||
{
|
||||
base.Disconnect();
|
||||
if (null != eventBinding)
|
||||
{
|
||||
eventBinding.VoiceEvents.OnStoppedListening.RemoveListener(OnStoppedListening);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnStoppedListening()
|
||||
{
|
||||
_isActive = false;
|
||||
}
|
||||
|
||||
public VoiceServiceRequest Activate(string text, WitRequestOptions requestOptions,
|
||||
VoiceServiceRequestEvents requestEvents)
|
||||
{
|
||||
if (requestOptions == null)
|
||||
{
|
||||
requestOptions = new WitRequestOptions();
|
||||
}
|
||||
requestOptions.Text = text;
|
||||
eventBinding.VoiceEvents.OnRequestOptionSetup?.Invoke(requestOptions);
|
||||
VoiceServiceRequest request = GetRequest(requestOptions, requestEvents, NLPRequestInputType.Text);
|
||||
request.Send();
|
||||
return request;
|
||||
}
|
||||
|
||||
public VoiceServiceRequest Activate(WitRequestOptions requestOptions,
|
||||
VoiceServiceRequestEvents requestEvents)
|
||||
{
|
||||
if (_isActive) return null;
|
||||
_isActive = true;
|
||||
if (requestOptions == null)
|
||||
{
|
||||
requestOptions = new WitRequestOptions();
|
||||
}
|
||||
eventBinding.VoiceEvents.OnRequestOptionSetup?.Invoke(requestOptions);
|
||||
VoiceServiceRequest request = GetRequest(requestOptions, requestEvents, NLPRequestInputType.Audio);
|
||||
request.ActivateAudio();
|
||||
return request;
|
||||
}
|
||||
|
||||
public VoiceServiceRequest ActivateImmediately(WitRequestOptions requestOptions,
|
||||
VoiceServiceRequestEvents requestEvents)
|
||||
{
|
||||
if (_isActive) return null;
|
||||
_isActive = true;
|
||||
if (requestOptions == null)
|
||||
{
|
||||
requestOptions = new WitRequestOptions();
|
||||
}
|
||||
eventBinding.VoiceEvents.OnRequestOptionSetup?.Invoke(requestOptions);
|
||||
VoiceServiceRequest request = GetRequest(requestOptions, requestEvents, NLPRequestInputType.Audio, true);
|
||||
request.ActivateAudio();
|
||||
return request;
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
{
|
||||
_isActive = false;
|
||||
foreach (var request in Requests)
|
||||
{
|
||||
if (request.InputType == NLPRequestInputType.Audio)
|
||||
{
|
||||
request.DeactivateAudio();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DeactivateAndAbortRequest()
|
||||
{
|
||||
_isActive = false;
|
||||
foreach (var request in Requests)
|
||||
{
|
||||
if (request.InputType == NLPRequestInputType.Audio)
|
||||
{
|
||||
request.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DeactivateAndAbortRequest(VoiceServiceRequest request)
|
||||
{
|
||||
if (!Requests.Contains(request))
|
||||
{
|
||||
return;
|
||||
}
|
||||
request.Cancel();
|
||||
}
|
||||
|
||||
public void OnServiceNotAvailable(string error, string message)
|
||||
{
|
||||
_isActive = false;
|
||||
_isServiceAvailable = false;
|
||||
OnServiceNotAvailableEvent?.Invoke();
|
||||
}
|
||||
|
||||
public VoiceEvents VoiceEvents
|
||||
{
|
||||
get => _baseVoiceService.VoiceEvents;
|
||||
set => _baseVoiceService.VoiceEvents = value;
|
||||
}
|
||||
|
||||
public TelemetryEvents TelemetryEvents
|
||||
{
|
||||
get => _baseVoiceService.TelemetryEvents;
|
||||
set => _baseVoiceService.TelemetryEvents = value;
|
||||
}
|
||||
|
||||
// Obtains a VoiceSDKImplRequest with specified parameters
|
||||
private VoiceServiceRequest GetRequest(WitRequestOptions requestOptions,
|
||||
VoiceServiceRequestEvents requestEvents,
|
||||
NLPRequestInputType inputType,
|
||||
bool audioImmediate = false)
|
||||
{
|
||||
VoiceSDKImplRequest request = new VoiceSDKImplRequest(service, inputType, audioImmediate, requestOptions, requestEvents);
|
||||
Requests.Add(request);
|
||||
request.Events.OnCancel.AddListener(OnRequestCanceled);
|
||||
request.Events.OnFailed.AddListener(OnRequestFailed);
|
||||
request.Events.OnSuccess.AddListener(OnRequestSuccess);
|
||||
request.Events.OnComplete.AddListener(OnRequestComplete);
|
||||
VoiceEvents?.OnRequestInitialized?.Invoke(request);
|
||||
return request;
|
||||
}
|
||||
|
||||
// Cancelation callback
|
||||
private void OnRequestCanceled(VoiceServiceRequest request)
|
||||
{
|
||||
// Ignore if missing
|
||||
if (!Requests.Contains(request))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Canceled
|
||||
VLog.D($"Request Canceled\nReason: {request.Results.Message}");
|
||||
VoiceEvents?.OnCanceled?.Invoke(request.Results.Message);
|
||||
if (!string.Equals(request.Results.Message, WitConstants.CANCEL_MESSAGE_PRE_SEND))
|
||||
{
|
||||
VoiceEvents?.OnAborted?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
// Failure callback
|
||||
private void OnRequestFailed(VoiceServiceRequest request)
|
||||
{
|
||||
// Ignore if missing
|
||||
if (!Requests.Contains(request))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Failed
|
||||
VLog.D($"Request Failed\nError: {request.Results.Message}");
|
||||
VoiceEvents?.OnError?.Invoke("HTTP Error " + request.Results.StatusCode, request.Results.Message);
|
||||
VoiceEvents?.OnRequestCompleted?.Invoke();
|
||||
}
|
||||
|
||||
// Success callback
|
||||
private void OnRequestSuccess(VoiceServiceRequest request)
|
||||
{
|
||||
// Ignore if missing
|
||||
if (!Requests.Contains(request))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Success
|
||||
VLog.D("Request Success");
|
||||
VoiceEvents?.OnResponse?.Invoke(request.Results.ResponseData);
|
||||
VoiceEvents?.OnRequestCompleted?.Invoke();
|
||||
}
|
||||
|
||||
// Request completed
|
||||
private void OnRequestComplete(VoiceServiceRequest request)
|
||||
{
|
||||
// Ignore if missing
|
||||
if (!Requests.Contains(request))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove listeners
|
||||
request.Events.OnCancel.RemoveListener(OnRequestCanceled);
|
||||
request.Events.OnFailed.RemoveListener(OnRequestFailed);
|
||||
request.Events.OnSuccess.RemoveListener(OnRequestSuccess);
|
||||
request.Events.OnComplete.RemoveListener(OnRequestComplete);
|
||||
|
||||
// Remove request
|
||||
Requests.Remove(request);
|
||||
VoiceEvents?.OnComplete?.Invoke(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3943048f6aa4a49977131e8fb7f677d
|
||||
timeCreated: 1630370598
|
||||
@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Meta.Voice;
|
||||
using Meta.WitAi.Json;
|
||||
using Meta.WitAi.Configuration;
|
||||
using Meta.WitAi.Requests;
|
||||
|
||||
namespace Oculus.Voice.Bindings.Android
|
||||
{
|
||||
/// <summary>
|
||||
/// A class generated by VoiceSDKImpl to track voice request calls
|
||||
/// </summary>
|
||||
public class VoiceSDKImplRequest : VoiceServiceRequest
|
||||
{
|
||||
public VoiceSDKBinding Service { get; private set; }
|
||||
public bool Immediately { get; private set; }
|
||||
|
||||
#region CALLS
|
||||
public VoiceSDKImplRequest(VoiceSDKBinding newService, NLPRequestInputType newInputType, bool newImmediately, WitRequestOptions newOptions,
|
||||
VoiceServiceRequestEvents newEvents) : base(newInputType, newOptions, newEvents)
|
||||
{
|
||||
Service = newService;
|
||||
Immediately = newImmediately;
|
||||
}
|
||||
|
||||
protected override void HandleAudioActivation()
|
||||
{
|
||||
if (Immediately)
|
||||
{
|
||||
Service.ActivateImmediately(Options);
|
||||
}
|
||||
else
|
||||
{
|
||||
Service.Activate(Options);
|
||||
}
|
||||
SetAudioInputState(VoiceAudioInputState.On);
|
||||
}
|
||||
|
||||
protected override void HandleAudioDeactivation()
|
||||
{
|
||||
Service.Deactivate();
|
||||
SetAudioInputState(VoiceAudioInputState.Off);
|
||||
}
|
||||
|
||||
protected override void HandleSend()
|
||||
{
|
||||
if (InputType == NLPRequestInputType.Text)
|
||||
{
|
||||
Service.Activate(Options.Text, Options);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void HandleCancel()
|
||||
{
|
||||
Service.DeactivateAndAbortRequest();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region EVENTS
|
||||
/// <summary>
|
||||
/// Called audio is now listening
|
||||
/// </summary>
|
||||
public void HandleStartListening()
|
||||
{
|
||||
//NOT YET IMPLEMENTED
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called audio is no longer listening
|
||||
/// </summary>
|
||||
public void HandleStopListening()
|
||||
{
|
||||
//NOT YET IMPLEMENTED
|
||||
}
|
||||
/// <summary>
|
||||
/// Callback when in progress response data has been received
|
||||
/// </summary>
|
||||
/// <param name="responseJson">The unparsed json data</param>
|
||||
public void HandlePartialResponse(string responseJson)
|
||||
{
|
||||
WitResponseNode responseData = WitResponseNode.Parse(responseJson);
|
||||
HandlePartialNlpResponse(responseData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called for partial transcription of text
|
||||
/// </summary>
|
||||
public void HandlePartialTranscription(string transcription)
|
||||
{
|
||||
ApplyTranscription(transcription, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called for final transcription of text
|
||||
/// </summary>
|
||||
public void HandleFullTranscription(string transcription)
|
||||
{
|
||||
ApplyTranscription(transcription, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transmission began
|
||||
/// </summary>
|
||||
public void HandleTransmissionBegan()
|
||||
{
|
||||
if (InputType == NLPRequestInputType.Audio)
|
||||
{
|
||||
Send();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when an error message has been received
|
||||
/// </summary>
|
||||
public void HandleCanceled()
|
||||
{
|
||||
HandleCancel();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when an error message has been received
|
||||
/// </summary>
|
||||
public void HandleError(string error, string message, string errorBody)
|
||||
{
|
||||
HandleFailure($"{error} - {message}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Callback when final response data has been received
|
||||
/// </summary>
|
||||
/// <param name="responseJson">The unparsed json data</param>
|
||||
public void HandleResponse(string responseJson)
|
||||
{
|
||||
WitResponseNode responseData = WitResponseNode.Parse(responseJson);
|
||||
HandleFinalNlpResponse(responseData, null);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f1f000e2fa84594da030e8e2d0b9c3b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,274 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Meta.WitAi;
|
||||
using Meta.WitAi.Events;
|
||||
using Meta.WitAi.Requests;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Voice.Bindings.Android
|
||||
{
|
||||
public class VoiceSDKListenerBinding : AndroidJavaProxy
|
||||
{
|
||||
private IVoiceService _voiceService;
|
||||
private readonly IVCBindingEvents _bindingEvents;
|
||||
|
||||
public VoiceEvents VoiceEvents => _voiceService.VoiceEvents;
|
||||
public TelemetryEvents TelemetryEvents => _voiceService.TelemetryEvents;
|
||||
|
||||
public enum StoppedListeningReason : int {
|
||||
NoReasonProvided = 0,
|
||||
Inactivity = 1,
|
||||
Timeout = 2,
|
||||
Deactivation = 3,
|
||||
}
|
||||
|
||||
public VoiceSDKListenerBinding(IVoiceService voiceService, IVCBindingEvents bindingEvents) : base(
|
||||
"com.oculus.assistant.api.voicesdk.immersivevoicecommands.IVCEventsListener")
|
||||
{
|
||||
_voiceService = voiceService;
|
||||
_bindingEvents = bindingEvents;
|
||||
}
|
||||
|
||||
// Get request for a specified request id
|
||||
private VoiceServiceRequest GetRequest(string requestId)
|
||||
{
|
||||
HashSet<VoiceServiceRequest> requests = _voiceService.Requests;
|
||||
if (requests == null || requests.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var request in requests)
|
||||
{
|
||||
string checkRequestId = request?.Options?.RequestId;
|
||||
if (string.Equals(requestId, checkRequestId))
|
||||
{
|
||||
return request;
|
||||
}
|
||||
}
|
||||
return requests.First();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Callback for listening start
|
||||
/// </summary>
|
||||
public void onStartListening(string requestId)
|
||||
{
|
||||
// Event callbacks
|
||||
VoiceEvents.OnStartListening?.Invoke();
|
||||
}
|
||||
public void onStartListening() => onStartListening(null);
|
||||
|
||||
/// <summary>
|
||||
/// Callback for listening completion
|
||||
/// </summary>
|
||||
public void onStoppedListening(int reason, string requestId)
|
||||
{
|
||||
// Request callbacks
|
||||
var request = GetRequest(requestId);
|
||||
|
||||
// Event callbacks
|
||||
VoiceEvents.OnStoppedListening?.Invoke();
|
||||
switch((StoppedListeningReason)reason){
|
||||
case StoppedListeningReason.NoReasonProvided:
|
||||
break;
|
||||
case StoppedListeningReason.Inactivity:
|
||||
VoiceEvents.OnStoppedListeningDueToInactivity?.Invoke();
|
||||
request.Cancel();
|
||||
break;
|
||||
case StoppedListeningReason.Timeout:
|
||||
VoiceEvents.OnStoppedListeningDueToTimeout?.Invoke();
|
||||
request.Cancel();
|
||||
break;
|
||||
case StoppedListeningReason.Deactivation:
|
||||
VoiceEvents.OnStoppedListeningDueToDeactivation?.Invoke();
|
||||
request.Cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void onStoppedListening(int reason) => onStoppedListening(reason, null);
|
||||
|
||||
/// <summary>
|
||||
/// Request submission callback
|
||||
/// </summary>
|
||||
/// <param name="requestId">The associated unique request identifier</param>
|
||||
public void onRequestCreated(string requestId)
|
||||
{
|
||||
// Request callbacks
|
||||
var request = GetRequest(requestId);
|
||||
if (request is VoiceSDKImplRequest implRequest)
|
||||
{
|
||||
implRequest.HandleTransmissionBegan();
|
||||
}
|
||||
|
||||
// Event callbacks
|
||||
#pragma warning disable CS0618
|
||||
VoiceEvents.OnRequestCreated?.Invoke(null);
|
||||
VoiceEvents.OnSend?.Invoke(null);
|
||||
}
|
||||
private void onRequestCreated() => onRequestCreated(null);
|
||||
|
||||
/// <summary>
|
||||
/// Partial transcription set
|
||||
/// </summary>
|
||||
/// <param name="transcription"></param>
|
||||
/// <param name="requestId"></param>
|
||||
public void onPartialTranscription(string transcription, string requestId)
|
||||
{
|
||||
// Request callbacks
|
||||
var request = GetRequest(requestId);
|
||||
if (request is VoiceSDKImplRequest implRequest)
|
||||
{
|
||||
implRequest.HandlePartialTranscription(transcription);
|
||||
}
|
||||
|
||||
// Partial transcription callback
|
||||
VoiceEvents.OnPartialTranscription?.Invoke(transcription);
|
||||
}
|
||||
public void onPartialTranscription(string transcription) => onPartialTranscription(transcription, null);
|
||||
|
||||
/// <summary>
|
||||
/// Final transcription received
|
||||
/// </summary>
|
||||
/// <param name="transcription"></param>
|
||||
/// <param name="requestId"></param>
|
||||
public void onFullTranscription(string transcription, string requestId)
|
||||
{
|
||||
// Request callbacks
|
||||
var request = GetRequest(requestId);
|
||||
if (request is VoiceSDKImplRequest implRequest)
|
||||
{
|
||||
implRequest.HandleFullTranscription(transcription);
|
||||
}
|
||||
|
||||
// Transcription callback
|
||||
VoiceEvents.OnFullTranscription?.Invoke(transcription);
|
||||
}
|
||||
public void onFullTranscription(string transcription) => onFullTranscription(transcription, null);
|
||||
|
||||
/// <summary>
|
||||
/// Callback when early response data has been received
|
||||
/// </summary>
|
||||
/// <param name="responseJson">The unparsed json data</param>
|
||||
/// <param name="requestId">The associated unique request identifier</param>
|
||||
public void onPartialResponse(string responseJson, string requestId)
|
||||
{
|
||||
var request = GetRequest(requestId);
|
||||
if (request is VoiceSDKImplRequest implRequest)
|
||||
{
|
||||
implRequest.HandlePartialResponse(responseJson);
|
||||
}
|
||||
}
|
||||
public void onPartialResponse(string responseJson) => onPartialResponse(responseJson, null);
|
||||
|
||||
/// <summary>
|
||||
/// Called when user request cancellation has occured
|
||||
/// </summary>
|
||||
/// <param name="requestId">The associated unique request identifier</param>
|
||||
public void onAborted(string requestId)
|
||||
{
|
||||
var request = GetRequest(requestId);
|
||||
if (request is VoiceSDKImplRequest implRequest)
|
||||
{
|
||||
implRequest.HandleCanceled();
|
||||
}
|
||||
}
|
||||
public void onAborted() => onAborted(null);
|
||||
|
||||
/// <summary>
|
||||
/// Called when an error message has been received
|
||||
/// </summary>
|
||||
/// <param name="error">The error itself</param>
|
||||
/// <param name="message">The error message</param>
|
||||
/// <param name="errorBody">The full body of the message</param>
|
||||
/// <param name="requestId">The associated unique request identifier</param>
|
||||
public void onError(string error, string message, string errorBody, string requestId)
|
||||
{
|
||||
var request = GetRequest(requestId);
|
||||
if (request is VoiceSDKImplRequest implRequest)
|
||||
{
|
||||
implRequest.HandleError(error, message, errorBody);
|
||||
}
|
||||
}
|
||||
public void onError(string error, string message, string errorBody) => onError(error, message, errorBody, null);
|
||||
|
||||
/// <summary>
|
||||
/// Callback when response data has been received
|
||||
/// </summary>
|
||||
/// <param name="responseJson">The unparsed json data</param>
|
||||
/// <param name="requestId">The associated unique request identifier</param>
|
||||
public void onResponse(string responseJson, string requestId)
|
||||
{
|
||||
var request = GetRequest(requestId);
|
||||
if (request is VoiceSDKImplRequest implRequest)
|
||||
{
|
||||
implRequest.HandleResponse(responseJson);
|
||||
}
|
||||
}
|
||||
public void onResponse(string responseJson) => onResponse(responseJson, null);
|
||||
|
||||
|
||||
public void onMicLevelChanged(float level, string requestId)
|
||||
{
|
||||
VoiceEvents.OnMicLevelChanged?.Invoke(level);
|
||||
}
|
||||
public void onMicLevelChanged(float level) => onMicLevelChanged(level, null);
|
||||
|
||||
public void onMicDataSent(string requestId)
|
||||
{
|
||||
VoiceEvents.OnMicDataSent?.Invoke();
|
||||
}
|
||||
public void onMicDataSent() => onMicDataSent(null);
|
||||
|
||||
public void onMinimumWakeThresholdHit(string requestId)
|
||||
{
|
||||
VoiceEvents.OnMinimumWakeThresholdHit?.Invoke();
|
||||
}
|
||||
public void onMinimumWakeThresholdHit() => onMinimumWakeThresholdHit(null);
|
||||
|
||||
public void onRequestCompleted(string requestId)
|
||||
{
|
||||
|
||||
}
|
||||
public void onRequestCompleted() => onRequestCompleted(null);
|
||||
|
||||
public void onServiceNotAvailable(string error, string message)
|
||||
{
|
||||
VLog.W($"Platform service is not available: {error} - {message}");
|
||||
_bindingEvents.OnServiceNotAvailable(error, message);
|
||||
}
|
||||
|
||||
public void onAudioDurationTrackerFinished(long timestamp, double duration)
|
||||
{
|
||||
long ticksElapsed = NativeTimestampToDateTime(timestamp).Ticks / TimeSpan.TicksPerMillisecond;
|
||||
TelemetryEvents.OnAudioTrackerFinished?.Invoke(ticksElapsed, duration);
|
||||
}
|
||||
|
||||
private DateTime NativeTimestampToDateTime(long javaTimestamp)
|
||||
{
|
||||
// Java timestamp is milliseconds past epoch
|
||||
DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
|
||||
return dateTime.AddMilliseconds(javaTimestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4812e4a88b84256a571c7253e27799f
|
||||
timeCreated: 1630371293
|
||||
3
Assets/Oculus/Voice/Scripts/Runtime/Interfaces.meta
Normal file
3
Assets/Oculus/Voice/Scripts/Runtime/Interfaces.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44a9302c8ca946f3b19b222b1481aa72
|
||||
timeCreated: 1630374670
|
||||
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Meta.WitAi;
|
||||
using Meta.WitAi.Configuration;
|
||||
|
||||
namespace Oculus.Voice.Interfaces
|
||||
{
|
||||
public interface IPlatformVoiceService : IVoiceService
|
||||
{
|
||||
bool PlatformSupportsWit { get; }
|
||||
|
||||
void SetRuntimeConfiguration(WitRuntimeConfiguration configuration);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64225fc2964c4ee98ff780eb51274278
|
||||
timeCreated: 1630374685
|
||||
8
Assets/Oculus/Voice/Scripts/Runtime/Logging.meta
Normal file
8
Assets/Oculus/Voice/Scripts/Runtime/Logging.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c07c66b29c0dcb14b97e28dd36111b7c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
264
Assets/Oculus/Voice/Scripts/Runtime/Logging/TTSServiceLogging.cs
Normal file
264
Assets/Oculus/Voice/Scripts/Runtime/Logging/TTSServiceLogging.cs
Normal file
@ -0,0 +1,264 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Meta.WitAi;
|
||||
using Meta.WitAi.Data.Configuration;
|
||||
using Meta.WitAi.Interfaces;
|
||||
using Meta.WitAi.Requests;
|
||||
using Meta.WitAi.TTS;
|
||||
using Meta.WitAi.TTS.Data;
|
||||
using Oculus.Voice.Core.Utilities;
|
||||
using Oculus.Voice.Core.Bindings.Android.PlatformLogger;
|
||||
using Oculus.Voice.Core.Bindings.Interfaces;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Voice.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// Script for logging various TTSService events
|
||||
/// </summary>
|
||||
public class TTSServiceLogging : MonoBehaviour
|
||||
{
|
||||
#region LOGGING
|
||||
/// <summary>
|
||||
/// Log output to console
|
||||
/// </summary>
|
||||
public bool EnableConsoleLogging = false;
|
||||
|
||||
/// <summary>
|
||||
/// The service being observed
|
||||
/// </summary>
|
||||
public TTSService Service { get; private set; }
|
||||
|
||||
// Logger
|
||||
private IVoiceSDKLogger _voiceSDKLoggerImpl;
|
||||
// Requests per request id
|
||||
private Dictionary<string, TTSServiceRequestLog> _requests = new Dictionary<string, TTSServiceRequestLog>();
|
||||
// Requests
|
||||
private struct TTSServiceRequestLog
|
||||
{
|
||||
public DateTime startTime;
|
||||
public Dictionary<string, string> annotations;
|
||||
}
|
||||
|
||||
// Annotation ids
|
||||
private const string TTS_FILETYPE_ANNOTATION = "ttsFileType";
|
||||
private const string TTS_FILESTREAM_ANNOTATION = "ttsFileStream";
|
||||
private const string TTS_START_TIME_ANNOTATION = "ttsStartTime";
|
||||
private const string TTS_FIRST_TIME_ANNOTATION = "ttsFirstResponseTime";
|
||||
private const string TTS_READY_TIME_ANNOTATION = "ttsReadyTime";
|
||||
private const string TTS_FINISH_TIME_ANNOTATION = "ttsFinishedTime";
|
||||
private const string TTS_ERROR_ANNOTATION = "ttsError";
|
||||
|
||||
// Add to every TTSService
|
||||
private void Awake()
|
||||
{
|
||||
Service = gameObject.GetComponent<TTSService>();
|
||||
InitLogger();
|
||||
}
|
||||
// Init logger
|
||||
private void InitLogger()
|
||||
{
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
// PI Logger
|
||||
var loggerImpl = new VoiceSDKPlatformLoggerImpl();
|
||||
loggerImpl.Connect(VoiceSDKConstants.SdkVersion);
|
||||
_voiceSDKLoggerImpl = loggerImpl;
|
||||
#else
|
||||
// Console Logger
|
||||
_voiceSDKLoggerImpl = new VoiceSDKConsoleLoggerImpl();
|
||||
#endif
|
||||
|
||||
// Get configuration
|
||||
WitConfiguration witConfig = Service.GetComponent<IWitConfigurationProvider>()?.Configuration;
|
||||
if (witConfig != null)
|
||||
{
|
||||
_voiceSDKLoggerImpl.WitApplication = witConfig.GetLoggerAppId();
|
||||
}
|
||||
}
|
||||
// Add events
|
||||
private void OnEnable()
|
||||
{
|
||||
if (_voiceSDKLoggerImpl != null)
|
||||
{
|
||||
_voiceSDKLoggerImpl.ShouldLogToConsole = EnableConsoleLogging;
|
||||
}
|
||||
if (Service)
|
||||
{
|
||||
Service.Events.WebRequest.OnRequestBegin.AddListener(OnRequestBegin);
|
||||
Service.Events.WebRequest.OnRequestCancel.AddListener(OnRequestCancel);
|
||||
Service.Events.WebRequest.OnRequestError.AddListener(OnRequestError);
|
||||
Service.Events.WebRequest.OnRequestFirstResponse.AddListener(OnRequestFirstResponse);
|
||||
Service.Events.WebRequest.OnRequestReady.AddListener(OnRequestReady);
|
||||
Service.Events.WebRequest.OnRequestComplete.AddListener(OnRequestComplete);
|
||||
}
|
||||
}
|
||||
// Remove events
|
||||
private void OnDisable()
|
||||
{
|
||||
if (Service)
|
||||
{
|
||||
Service.Events.WebRequest.OnRequestBegin.RemoveListener(OnRequestBegin);
|
||||
Service.Events.WebRequest.OnRequestCancel.RemoveListener(OnRequestCancel);
|
||||
Service.Events.WebRequest.OnRequestError.RemoveListener(OnRequestError);
|
||||
Service.Events.WebRequest.OnRequestFirstResponse.RemoveListener(OnRequestFirstResponse);
|
||||
Service.Events.WebRequest.OnRequestReady.RemoveListener(OnRequestReady);
|
||||
Service.Events.WebRequest.OnRequestComplete.RemoveListener(OnRequestComplete);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRequestBegin(TTSClipData clipData)
|
||||
{
|
||||
LogStart(clipData);
|
||||
}
|
||||
private void OnRequestCancel(TTSClipData clipData)
|
||||
{
|
||||
LogComplete(clipData, "aborted");
|
||||
}
|
||||
private void OnRequestError(TTSClipData clipData, string error)
|
||||
{
|
||||
LogComplete(clipData, error);
|
||||
}
|
||||
private void OnRequestFirstResponse(TTSClipData clipData)
|
||||
{
|
||||
LogTimestamp(clipData, TTS_FIRST_TIME_ANNOTATION);
|
||||
}
|
||||
private void OnRequestReady(TTSClipData clipData)
|
||||
{
|
||||
LogTimestamp(clipData, TTS_READY_TIME_ANNOTATION);
|
||||
}
|
||||
private void OnRequestComplete(TTSClipData clipData)
|
||||
{
|
||||
LogComplete(clipData);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region LOG HELPERS
|
||||
// Generate request data & apply initial annotations
|
||||
private void LogStart(TTSClipData clipData)
|
||||
{
|
||||
TTSServiceRequestLog requestData = GetRequestData(clipData);
|
||||
requestData.startTime = DateTime.Now;
|
||||
requestData.annotations = new Dictionary<string, string>();
|
||||
LogTimestamp(requestData, TTS_START_TIME_ANNOTATION);
|
||||
LogAnnotate(requestData, TTS_FILETYPE_ANNOTATION, AudioStreamHandler.GetDecodeType(clipData.audioType).ToString());
|
||||
LogAnnotate(requestData, TTS_FILESTREAM_ANNOTATION, clipData.queryStream.ToString(CultureInfo.InvariantCulture));
|
||||
_requests[clipData.queryRequestId] = requestData;
|
||||
}
|
||||
// Get request data
|
||||
private TTSServiceRequestLog GetRequestData(TTSClipData clipData)
|
||||
{
|
||||
if (_requests.ContainsKey(clipData.queryRequestId))
|
||||
{
|
||||
return _requests[clipData.queryRequestId];
|
||||
}
|
||||
return new TTSServiceRequestLog();
|
||||
}
|
||||
// Append the elapsed ms
|
||||
private void LogTimestamp(TTSClipData clipData, string key)
|
||||
{
|
||||
LogTimestamp(GetRequestData(clipData), key);
|
||||
}
|
||||
// Append the elapsed ms
|
||||
private void LogTimestamp(TTSServiceRequestLog requestData, string key)
|
||||
{
|
||||
LogAnnotate(requestData, key, DateTimeUtility.ElapsedMilliseconds.ToString());
|
||||
}
|
||||
// Append if possible
|
||||
private void LogAnnotate(TTSServiceRequestLog requestData, string key, string value)
|
||||
{
|
||||
if (requestData.annotations != null)
|
||||
{
|
||||
requestData.annotations[key] = value;
|
||||
}
|
||||
}
|
||||
// Append if possible
|
||||
private void LogComplete(TTSClipData clipData, string error = null)
|
||||
{
|
||||
// Get data & ensure annotations exist
|
||||
TTSServiceRequestLog requestData = GetRequestData(clipData);
|
||||
if (requestData.annotations == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Add error & completion time
|
||||
if (!string.IsNullOrEmpty(error))
|
||||
{
|
||||
LogAnnotate(requestData, TTS_ERROR_ANNOTATION, error);
|
||||
}
|
||||
LogTimestamp(requestData, TTS_FINISH_TIME_ANNOTATION);
|
||||
|
||||
// Send full log
|
||||
if (_voiceSDKLoggerImpl != null)
|
||||
{
|
||||
_voiceSDKLoggerImpl.LogInteractionStart(clipData.queryRequestId, WitConstants.ENDPOINT_TTS);
|
||||
foreach (var key in requestData.annotations.Keys)
|
||||
{
|
||||
_voiceSDKLoggerImpl.LogAnnotation(key, requestData.annotations[key]);
|
||||
}
|
||||
if (string.IsNullOrEmpty(error))
|
||||
{
|
||||
_voiceSDKLoggerImpl.LogInteractionEndSuccess();
|
||||
}
|
||||
else
|
||||
{
|
||||
_voiceSDKLoggerImpl.LogInteractionEndFailure(error);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove cache
|
||||
_requests.Remove(clipData.queryRequestId);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region LOG GENERATION
|
||||
// Whether
|
||||
private static bool _initialized = false;
|
||||
|
||||
// On load, add callback
|
||||
[RuntimeInitializeOnLoadMethod]
|
||||
private static void Init()
|
||||
{
|
||||
// Only initialize if not previously done
|
||||
if (_initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_initialized = true;
|
||||
|
||||
// Add generation methods
|
||||
TTSService.OnServiceStart += OnServiceStart;
|
||||
}
|
||||
|
||||
// When a TTSService is generated, add a TTSServiceLogging script
|
||||
private static void OnServiceStart(TTSService service)
|
||||
{
|
||||
if (service != null && service.GetComponent<TTSServiceLogging>() == null)
|
||||
{
|
||||
service.gameObject.AddComponent<TTSServiceLogging>();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1de783830b1db62488c8d1414e71a8ba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Oculus/Voice/Scripts/Runtime/Service.meta
Normal file
8
Assets/Oculus/Voice/Scripts/Runtime/Service.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8e4f817930837444a893fce723ba3f6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
171
Assets/Oculus/Voice/Scripts/Runtime/Service/AppBuiltIns.cs
Normal file
171
Assets/Oculus/Voice/Scripts/Runtime/Service/AppBuiltIns.cs
Normal file
@ -0,0 +1,171 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Oculus.Voice
|
||||
{
|
||||
public static class AppBuiltIns
|
||||
{
|
||||
public static string builtInPrefix = "builtin:";
|
||||
private static string modelName = "Built-in Models";
|
||||
|
||||
public static readonly Dictionary<string, Dictionary<string, string>>
|
||||
apps = new Dictionary<string, Dictionary<string, string>>
|
||||
{
|
||||
{
|
||||
"Chinese", new Dictionary<string, string>
|
||||
{
|
||||
{"id", "voiceSDK_zh"},
|
||||
{"name", modelName},
|
||||
{"lang", "zh"},
|
||||
{"clientToken", "3KQH33637TAT7WD4TG7T65SDRO73WZGY"},
|
||||
}
|
||||
},
|
||||
{
|
||||
"Dutch", new Dictionary<string, string>
|
||||
{
|
||||
{"id", "voiceSDK_nl"},
|
||||
{"name", modelName},
|
||||
{"lang", "nl"},
|
||||
{"clientToken", "ZCD6HCNCL6GTJKZ3QKWNKQVEDI4GUL7C"},
|
||||
}
|
||||
},
|
||||
{
|
||||
"English", new Dictionary<string, string>
|
||||
{
|
||||
{"id", "voiceSDK_en"},
|
||||
{"name", modelName},
|
||||
{"lang", "en"},
|
||||
{"clientToken", "HOKEABS7HPIQVSRSVWRPTTV75TQJ5QBP"},
|
||||
}
|
||||
},
|
||||
{
|
||||
"French", new Dictionary<string, string>
|
||||
{
|
||||
{"id", "voiceSDK_fr"},
|
||||
{"name", modelName},
|
||||
{"lang", "fr"},
|
||||
{"clientToken", "7PP7NK2QAH67MREGZV6SB6RIEWAYDNRY"},
|
||||
}
|
||||
},
|
||||
{
|
||||
"German", new Dictionary<string, string>
|
||||
{
|
||||
{"id", "voiceSDK_de"},
|
||||
{"name", modelName},
|
||||
{"lang", "de"},
|
||||
{"clientToken", "7LXOOB4JC7MXPUTTGQHDVQMHGEEJT6LE"},
|
||||
}
|
||||
},
|
||||
{
|
||||
"Italian", new Dictionary<string, string>
|
||||
{
|
||||
{"id", "voiceSDK_it"},
|
||||
{"name", modelName},
|
||||
{"lang", "it"},
|
||||
{"clientToken", "KELCNR4DCCPPOCF2RDFS4M6JOCWWIFII"},
|
||||
}
|
||||
},
|
||||
{
|
||||
"Japanese", new Dictionary<string, string>
|
||||
{
|
||||
{"id", "voiceSDK_ja"},
|
||||
{"name", modelName},
|
||||
{"lang", "ja"},
|
||||
{"clientToken", "TPJGLBBCHJ5F7BVVN5XLEGP6YDQRUE3P"},
|
||||
}
|
||||
},
|
||||
{
|
||||
"Korean", new Dictionary<string, string>
|
||||
{
|
||||
{"id", "voiceSDK_ko"},
|
||||
{"name", modelName},
|
||||
{"lang", "ko"},
|
||||
{"clientToken", "NT4WJLL7ACMFBXS4B7W5GRLTKDZQ36R4"},
|
||||
}
|
||||
},
|
||||
{
|
||||
"Polish", new Dictionary<string, string>
|
||||
{
|
||||
{"id", "voiceSDK_pl"},
|
||||
{"name", modelName},
|
||||
{"lang", "pl"},
|
||||
{"clientToken", "DMDRHGYDYN33D3IKCX5BG5R57EL2IIC4"},
|
||||
}
|
||||
},
|
||||
{
|
||||
"Portuguese", new Dictionary<string, string>
|
||||
{
|
||||
{"id", "voiceSDK_pt"},
|
||||
{"name", modelName},
|
||||
{"lang", "pt"},
|
||||
{"clientToken", "W4W3BSKL72HZC5MXLILONJUCG732SQQN"},
|
||||
}
|
||||
},
|
||||
{
|
||||
"Russian", new Dictionary<string, string>
|
||||
{
|
||||
{"id", "voiceSDK_ru"},
|
||||
{"name", modelName},
|
||||
{"lang", "ru"},
|
||||
{"clientToken", "W67HLUWA3MBYVEKRW3VVWUKSNZGAOFBI"},
|
||||
}
|
||||
},
|
||||
{
|
||||
"Spanish", new Dictionary<string, string>
|
||||
{
|
||||
{"id", "voiceSDK_es"},
|
||||
{"name", modelName},
|
||||
{"lang", "es"},
|
||||
{"clientToken", "YW7AM5OOVSW5XKGYKFE2S2HLC2WHC3UI"},
|
||||
}
|
||||
},
|
||||
{
|
||||
"Swedish", new Dictionary<string, string>
|
||||
{
|
||||
{"id", "voiceSDK_sv"},
|
||||
{"name", modelName},
|
||||
{"lang", "sv"},
|
||||
{"clientToken", "NPE3UJ7Y4NIVTUOZ7QPPAP3TY6FYPXJY"},
|
||||
}
|
||||
},
|
||||
{
|
||||
"Turkish", new Dictionary<string, string>
|
||||
{
|
||||
{"id", "voiceSDK_tr"},
|
||||
{"name", modelName},
|
||||
{"lang", "tr"},
|
||||
{"clientToken", "ZCISEDXESLYJOROLNOODCGGPZXHLUAEE"},
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
public static string[] appNames
|
||||
{
|
||||
get
|
||||
{
|
||||
string[] keys = new string[apps.Keys.Count];
|
||||
apps.Keys.CopyTo(keys, 0);
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6483d6b21054c4e07acfd6c1c43c4e0b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,454 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Meta.Voice;
|
||||
using Meta.WitAi;
|
||||
using Meta.WitAi.Configuration;
|
||||
using Meta.WitAi.Data;
|
||||
using Meta.WitAi.Data.Configuration;
|
||||
using Meta.WitAi.Interfaces;
|
||||
using Meta.WitAi.Json;
|
||||
using Meta.WitAi.Requests;
|
||||
using Oculus.Voice.Bindings.Android;
|
||||
using Oculus.Voice.Core.Bindings.Android.PlatformLogger;
|
||||
using Oculus.Voice.Core.Bindings.Interfaces;
|
||||
using Oculus.Voice.Interfaces;
|
||||
using Oculus.VoiceSDK.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Voice
|
||||
{
|
||||
[HelpURL("https://developer.oculus.com/experimental/voice-sdk/tutorial-overview/")]
|
||||
public class AppVoiceExperience : VoiceService, IWitRuntimeConfigProvider, IWitConfigurationProvider
|
||||
{
|
||||
[SerializeField] private WitRuntimeConfiguration witRuntimeConfiguration;
|
||||
[Tooltip("Uses platform services to access wit.ai instead of accessing wit directly from within the application.")]
|
||||
[SerializeField] private bool usePlatformServices;
|
||||
|
||||
[Tooltip("Enables logs related to the interaction to be displayed on console")]
|
||||
[SerializeField] private bool enableConsoleLogging;
|
||||
|
||||
public WitRuntimeConfiguration RuntimeConfiguration
|
||||
{
|
||||
get => witRuntimeConfiguration;
|
||||
set => witRuntimeConfiguration = value;
|
||||
}
|
||||
|
||||
public WitConfiguration Configuration => witRuntimeConfiguration?.witConfiguration;
|
||||
|
||||
private IPlatformVoiceService platformService;
|
||||
private IVoiceService voiceServiceImpl;
|
||||
private IVoiceSDKLogger voiceSDKLoggerImpl;
|
||||
|
||||
private static string PACKAGE_VERSION => VoiceSDKConstants.SdkVersion;
|
||||
|
||||
private bool Initialized => null != voiceServiceImpl;
|
||||
|
||||
public event Action OnInitialized;
|
||||
|
||||
#region Voice Service Properties
|
||||
public override bool Active => base.Active || (null != voiceServiceImpl && voiceServiceImpl.Active);
|
||||
public override bool IsRequestActive => base.IsRequestActive || (null != voiceServiceImpl && voiceServiceImpl.IsRequestActive);
|
||||
public override ITranscriptionProvider TranscriptionProvider
|
||||
{
|
||||
get => voiceServiceImpl?.TranscriptionProvider;
|
||||
set
|
||||
{
|
||||
if (voiceServiceImpl != null)
|
||||
{
|
||||
voiceServiceImpl.TranscriptionProvider = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
public override bool MicActive => null != voiceServiceImpl && voiceServiceImpl.MicActive;
|
||||
protected override bool ShouldSendMicData => witRuntimeConfiguration.sendAudioToWit ||
|
||||
null == TranscriptionProvider;
|
||||
#endregion
|
||||
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
public bool HasPlatformIntegrations => usePlatformServices && voiceServiceImpl is VoiceSDKImpl;
|
||||
#else
|
||||
public bool HasPlatformIntegrations => false;
|
||||
#endif
|
||||
|
||||
public bool EnableConsoleLogging => enableConsoleLogging;
|
||||
|
||||
public override bool UsePlatformIntegrations
|
||||
{
|
||||
get => usePlatformServices;
|
||||
set
|
||||
{
|
||||
// If we're trying to turn on platform services and they're not currently active we
|
||||
// will forcibly reinit and try to set the state.
|
||||
if (usePlatformServices != value || HasPlatformIntegrations != value)
|
||||
{
|
||||
usePlatformServices = value;
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
Debug.Log($"{(usePlatformServices ? "Enabling" : "Disabling")} platform integration.");
|
||||
InitVoiceSDK();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Voice Service Text Methods
|
||||
public override bool CanSend()
|
||||
{
|
||||
return base.CanSend() && null != voiceServiceImpl && voiceServiceImpl.CanSend();
|
||||
}
|
||||
|
||||
public override VoiceServiceRequest Activate(string text, WitRequestOptions requestOptions, VoiceServiceRequestEvents requestEvents)
|
||||
{
|
||||
if (CanSend())
|
||||
{
|
||||
return voiceServiceImpl.Activate(text, requestOptions, requestEvents);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Voice Service Audio Methods
|
||||
public override bool CanActivateAudio()
|
||||
{
|
||||
return base.CanActivateAudio() && voiceServiceImpl.CanActivateAudio();
|
||||
}
|
||||
|
||||
protected override string GetActivateAudioError()
|
||||
{
|
||||
if (!HasPlatformIntegrations && !AudioBuffer.Instance.IsInputAvailable)
|
||||
{
|
||||
return "No Microphone(s)/recording devices found. You will be unable to capture audio on this device.";
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public override VoiceServiceRequest Activate(WitRequestOptions requestOptions, VoiceServiceRequestEvents requestEvents)
|
||||
{
|
||||
if (CanActivateAudio() && CanSend())
|
||||
{
|
||||
return voiceServiceImpl.Activate(requestOptions, requestEvents);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override VoiceServiceRequest ActivateImmediately(WitRequestOptions requestOptions, VoiceServiceRequestEvents requestEvents)
|
||||
{
|
||||
if (CanActivateAudio() && CanSend())
|
||||
{
|
||||
return voiceServiceImpl.ActivateImmediately(requestOptions, requestEvents);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void Deactivate()
|
||||
{
|
||||
voiceServiceImpl.Deactivate();
|
||||
}
|
||||
|
||||
public override void DeactivateAndAbortRequest()
|
||||
{
|
||||
voiceServiceImpl.DeactivateAndAbortRequest();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void InitVoiceSDK()
|
||||
{
|
||||
// Check voice sdk version
|
||||
if (string.IsNullOrEmpty(PACKAGE_VERSION))
|
||||
{
|
||||
VLog.E("No SDK Version Set");
|
||||
}
|
||||
|
||||
// Clean up if we're switching to native C# wit impl
|
||||
if (!UsePlatformIntegrations)
|
||||
{
|
||||
if (voiceServiceImpl is VoiceSDKImpl)
|
||||
{
|
||||
((VoiceSDKImpl) voiceServiceImpl).Disconnect();
|
||||
}
|
||||
|
||||
if (voiceSDKLoggerImpl is VoiceSDKPlatformLoggerImpl)
|
||||
{
|
||||
try
|
||||
{
|
||||
((VoiceSDKPlatformLoggerImpl)voiceSDKLoggerImpl).Disconnect();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VLog.E($"Disconnection error: {e.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
var loggerImpl = new VoiceSDKPlatformLoggerImpl();
|
||||
loggerImpl.Connect(PACKAGE_VERSION);
|
||||
voiceSDKLoggerImpl = loggerImpl;
|
||||
|
||||
if (UsePlatformIntegrations)
|
||||
{
|
||||
Debug.Log("Checking platform capabilities...");
|
||||
var platformImpl = new VoiceSDKImpl(this);
|
||||
platformImpl.OnServiceNotAvailableEvent += () => RevertToWitUnity();
|
||||
platformImpl.Connect(PACKAGE_VERSION);
|
||||
platformImpl.SetRuntimeConfiguration(RuntimeConfiguration);
|
||||
if (platformImpl.PlatformSupportsWit)
|
||||
{
|
||||
voiceServiceImpl = platformImpl;
|
||||
|
||||
if (voiceServiceImpl is Wit wit)
|
||||
{
|
||||
wit.RuntimeConfiguration = witRuntimeConfiguration;
|
||||
}
|
||||
|
||||
voiceServiceImpl.VoiceEvents = VoiceEvents;
|
||||
voiceServiceImpl.TelemetryEvents = TelemetryEvents;
|
||||
voiceSDKLoggerImpl.IsUsingPlatformIntegration = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Platform registration indicated platform support is not currently available.");
|
||||
RevertToWitUnity();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RevertToWitUnity();
|
||||
}
|
||||
#else
|
||||
voiceSDKLoggerImpl = new VoiceSDKConsoleLoggerImpl();
|
||||
RevertToWitUnity();
|
||||
#endif
|
||||
voiceSDKLoggerImpl.WitApplication = RuntimeConfiguration?.witConfiguration?.GetLoggerAppId();
|
||||
voiceSDKLoggerImpl.ShouldLogToConsole = EnableConsoleLogging;
|
||||
|
||||
OnInitialized?.Invoke();
|
||||
}
|
||||
|
||||
private void RevertToWitUnity()
|
||||
{
|
||||
Wit w = GetComponent<Wit>();
|
||||
if (null == w)
|
||||
{
|
||||
w = gameObject.AddComponent<Wit>();
|
||||
w.hideFlags = HideFlags.HideInInspector;
|
||||
}
|
||||
voiceServiceImpl = w;
|
||||
|
||||
if (voiceServiceImpl is Wit wit)
|
||||
{
|
||||
wit.RuntimeConfiguration = witRuntimeConfiguration;
|
||||
}
|
||||
|
||||
voiceServiceImpl.VoiceEvents = VoiceEvents;
|
||||
voiceServiceImpl.TelemetryEvents = TelemetryEvents;
|
||||
voiceSDKLoggerImpl.IsUsingPlatformIntegration = false;
|
||||
}
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
if (MicPermissionsManager.HasMicPermission())
|
||||
{
|
||||
InitVoiceSDK();
|
||||
}
|
||||
else
|
||||
{
|
||||
MicPermissionsManager.RequestMicPermission();
|
||||
}
|
||||
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
platformService?.SetRuntimeConfiguration(witRuntimeConfiguration);
|
||||
#endif
|
||||
|
||||
// Listeners
|
||||
VoiceEvents.OnRequestInitialized?.AddListener(OnRequestInit);
|
||||
VoiceEvents.OnResponse?.AddListener(OnWitResponseListener);
|
||||
VoiceEvents.OnStartListening?.AddListener(OnStartedListening);
|
||||
VoiceEvents.OnMinimumWakeThresholdHit?.AddListener(OnMinimumWakeThresholdHit);
|
||||
VoiceEvents.OnStoppedListening?.AddListener(OnStoppedListening);
|
||||
VoiceEvents.OnMicDataSent?.AddListener(OnMicDataSent);
|
||||
VoiceEvents.OnSend?.AddListener(OnSend);
|
||||
VoiceEvents.OnPartialTranscription?.AddListener(OnPartialTranscription);
|
||||
VoiceEvents.OnFullTranscription?.AddListener(OnFullTranscription);
|
||||
VoiceEvents.OnStoppedListeningDueToTimeout?.AddListener(OnStoppedListeningDueToTimeout);
|
||||
VoiceEvents.OnStoppedListeningDueToInactivity?.AddListener(OnStoppedListeningDueToInactivity);
|
||||
VoiceEvents.OnStoppedListeningDueToDeactivation?.AddListener(OnStoppedListeningDueToDeactivation);
|
||||
VoiceEvents.OnComplete?.AddListener(OnRequestComplete);
|
||||
TelemetryEvents.OnAudioTrackerFinished?.AddListener(OnAudioDurationTrackerFinished);
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
#if UNITY_ANDROID
|
||||
if (voiceServiceImpl is VoiceSDKImpl platformImpl)
|
||||
{
|
||||
platformImpl.Disconnect();
|
||||
}
|
||||
|
||||
if (voiceSDKLoggerImpl is VoiceSDKPlatformLoggerImpl loggerImpl)
|
||||
{
|
||||
loggerImpl.Disconnect();
|
||||
}
|
||||
#endif
|
||||
voiceServiceImpl = null;
|
||||
voiceSDKLoggerImpl = null;
|
||||
|
||||
// Listeners
|
||||
VoiceEvents.OnRequestInitialized?.RemoveListener(OnRequestInit);
|
||||
VoiceEvents.OnResponse?.RemoveListener(OnWitResponseListener);
|
||||
VoiceEvents.OnStartListening?.RemoveListener(OnStartedListening);
|
||||
VoiceEvents.OnMinimumWakeThresholdHit?.RemoveListener(OnMinimumWakeThresholdHit);
|
||||
VoiceEvents.OnStoppedListening?.RemoveListener(OnStoppedListening);
|
||||
VoiceEvents.OnMicDataSent?.RemoveListener(OnMicDataSent);
|
||||
VoiceEvents.OnSend?.RemoveListener(OnSend);
|
||||
VoiceEvents.OnPartialTranscription?.RemoveListener(OnPartialTranscription);
|
||||
VoiceEvents.OnFullTranscription?.RemoveListener(OnFullTranscription);
|
||||
VoiceEvents.OnStoppedListeningDueToTimeout?.RemoveListener(OnStoppedListeningDueToTimeout);
|
||||
VoiceEvents.OnStoppedListeningDueToInactivity?.RemoveListener(OnStoppedListeningDueToInactivity);
|
||||
VoiceEvents.OnStoppedListeningDueToDeactivation?.RemoveListener(OnStoppedListeningDueToDeactivation);
|
||||
VoiceEvents.OnComplete?.RemoveListener(OnRequestComplete);
|
||||
TelemetryEvents.OnAudioTrackerFinished?.RemoveListener(OnAudioDurationTrackerFinished);
|
||||
}
|
||||
|
||||
private void OnApplicationFocus(bool hasFocus)
|
||||
{
|
||||
if (enabled && hasFocus && !Initialized)
|
||||
{
|
||||
if (MicPermissionsManager.HasMicPermission())
|
||||
{
|
||||
InitVoiceSDK();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Event listeners for logging
|
||||
void OnRequestInit(VoiceServiceRequest request)
|
||||
{
|
||||
voiceSDKLoggerImpl.LogInteractionStart(request.Options?.RequestId, request.InputType == NLPRequestInputType.Text ? "message" : "speech");
|
||||
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
voiceSDKLoggerImpl.LogAnnotation("clientSDKVersion", PACKAGE_VERSION);
|
||||
#endif
|
||||
voiceSDKLoggerImpl.LogAnnotation("minWakeThreshold",
|
||||
RuntimeConfiguration?.soundWakeThreshold.ToString(CultureInfo.InvariantCulture));
|
||||
voiceSDKLoggerImpl.LogAnnotation("minKeepAliveTimeSec",
|
||||
RuntimeConfiguration?.minKeepAliveTimeInSeconds.ToString(CultureInfo.InvariantCulture));
|
||||
voiceSDKLoggerImpl.LogAnnotation("minTranscriptionKeepAliveTimeSec",
|
||||
RuntimeConfiguration?.minTranscriptionKeepAliveTimeInSeconds.ToString(CultureInfo.InvariantCulture));
|
||||
voiceSDKLoggerImpl.LogAnnotation("maxRecordingTime",
|
||||
RuntimeConfiguration?.maxRecordingTime.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
void OnWitResponseListener(WitResponseNode witResponseNode)
|
||||
{
|
||||
var tokens = witResponseNode?["speech"]?["tokens"];
|
||||
if (tokens != null)
|
||||
{
|
||||
int speechTokensLength = tokens.Count;
|
||||
string speechLength = witResponseNode["speech"]["tokens"][speechTokensLength - 1]?["end"]?.Value;
|
||||
voiceSDKLoggerImpl.LogAnnotation("audioLength", speechLength);
|
||||
}
|
||||
}
|
||||
|
||||
void OnStartedListening()
|
||||
{
|
||||
voiceSDKLoggerImpl.LogInteractionPoint("startedListening");
|
||||
}
|
||||
|
||||
void OnMinimumWakeThresholdHit()
|
||||
{
|
||||
voiceSDKLoggerImpl.LogInteractionPoint("minWakeThresholdHit");
|
||||
}
|
||||
|
||||
void OnStoppedListening()
|
||||
{
|
||||
voiceSDKLoggerImpl.LogInteractionPoint("stoppedListening");
|
||||
}
|
||||
|
||||
void OnStoppedListeningDueToTimeout()
|
||||
{
|
||||
voiceSDKLoggerImpl.LogInteractionPoint("stoppedListeningTimeout");
|
||||
}
|
||||
|
||||
void OnStoppedListeningDueToInactivity()
|
||||
{
|
||||
voiceSDKLoggerImpl.LogInteractionPoint("stoppedListeningInactivity");
|
||||
}
|
||||
|
||||
void OnStoppedListeningDueToDeactivation()
|
||||
{
|
||||
voiceSDKLoggerImpl.LogInteractionPoint("stoppedListeningDeactivate");
|
||||
}
|
||||
|
||||
void OnMicDataSent()
|
||||
{
|
||||
voiceSDKLoggerImpl.LogInteractionPoint("micDataSent");
|
||||
}
|
||||
|
||||
void OnSend(VoiceServiceRequest request)
|
||||
{
|
||||
voiceSDKLoggerImpl.LogInteractionPoint("witRequestCreated");
|
||||
if (request != null)
|
||||
{
|
||||
voiceSDKLoggerImpl.LogAnnotation("requestIdOverride", request.Options?.RequestId);
|
||||
}
|
||||
}
|
||||
|
||||
void OnAudioDurationTrackerFinished(long timestamp, double audioDuration)
|
||||
{
|
||||
voiceSDKLoggerImpl.LogAnnotation("adt_duration", audioDuration.ToString(CultureInfo.InvariantCulture));
|
||||
voiceSDKLoggerImpl.LogAnnotation("adt_finished", timestamp.ToString());
|
||||
}
|
||||
|
||||
void OnPartialTranscription(string text)
|
||||
{
|
||||
voiceSDKLoggerImpl.LogFirstTranscriptionTime();
|
||||
}
|
||||
|
||||
void OnFullTranscription(string text)
|
||||
{
|
||||
voiceSDKLoggerImpl.LogInteractionPoint("fullTranscriptionTime");
|
||||
}
|
||||
|
||||
void OnRequestComplete(VoiceServiceRequest request)
|
||||
{
|
||||
if (request.State == VoiceRequestState.Failed)
|
||||
{
|
||||
VLog.E($"Request Failed\nError: {request.Results.Message}\n{request.Results.ResponseData}");
|
||||
voiceSDKLoggerImpl.LogInteractionEndFailure(request.Results.Message);
|
||||
}
|
||||
else if (request.State == VoiceRequestState.Canceled)
|
||||
{
|
||||
VLog.D($"Request Canceled\nMessage: {request.Results.Message}");
|
||||
voiceSDKLoggerImpl.LogInteractionEndFailure("aborted");
|
||||
}
|
||||
else
|
||||
{
|
||||
VLog.D($"Request Success");
|
||||
voiceSDKLoggerImpl.LogInteractionEndSuccess();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28779cfed47441a42a6cd4fb49c8dc89
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,161 @@
|
||||
/*
|
||||
* 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.Configuration;
|
||||
using Meta.WitAi.Events;
|
||||
using Meta.WitAi.Requests;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace Oculus.Voice
|
||||
{
|
||||
public class ObjectVoiceExperience : MonoBehaviour
|
||||
{
|
||||
// TODO: T149927662 Clean FormerlySerializedAs in a follow up diff before release.
|
||||
[FormerlySerializedAs("voiceEvents")]
|
||||
[SerializeField] private VoiceEvents _voiceEvents = new VoiceEvents();
|
||||
|
||||
private AppVoiceExperience _voice;
|
||||
private VoiceServiceRequest _activation;
|
||||
private VoiceServiceRequestEvents _events = new VoiceServiceRequestEvents();
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (!_voice) _voice = FindObjectOfType<AppVoiceExperience>();
|
||||
|
||||
_events.OnCancel.AddListener(HandleCancel);
|
||||
_events.OnComplete.AddListener(HandleComplete);
|
||||
_events.OnFailed.AddListener(HandleFailed);
|
||||
_events.OnInit.AddListener(HandleInit);
|
||||
_events.OnSend.AddListener(HandleSend);
|
||||
_events.OnSuccess.AddListener(HandleSuccess);
|
||||
_events.OnAudioActivation.AddListener(HandleAudioActivation);
|
||||
_events.OnAudioDeactivation.AddListener(HandleAudioDeactivation);
|
||||
_events.OnPartialTranscription.AddListener(HandlePartialTranscription);
|
||||
_events.OnFullTranscription.AddListener(HandleFullTranscription);
|
||||
_events.OnStateChange.AddListener(HandleStateChange);
|
||||
_events.OnStartListening.AddListener(HandleStartListening);
|
||||
_events.OnStopListening.AddListener(HandleStopListening);
|
||||
_events.OnDownloadProgressChange.AddListener(HandleDownloadProgressChange);
|
||||
_events.OnUploadProgressChange.AddListener(HandleUploadProgressChange);
|
||||
_events.OnAudioInputStateChange.AddListener(HandleAudioInputStateChange);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_events.OnCancel.RemoveListener(HandleCancel);
|
||||
_events.OnComplete.RemoveListener(HandleComplete);
|
||||
_events.OnFailed.RemoveListener(HandleFailed);
|
||||
_events.OnInit.RemoveListener(HandleInit);
|
||||
_events.OnSend.RemoveListener(HandleSend);
|
||||
_events.OnSuccess.RemoveListener(HandleSuccess);
|
||||
_events.OnAudioActivation.RemoveListener(HandleAudioActivation);
|
||||
_events.OnAudioDeactivation.RemoveListener(HandleAudioDeactivation);
|
||||
_events.OnFullTranscription.RemoveListener(HandleFullTranscription);
|
||||
_events.OnPartialTranscription.RemoveListener(HandlePartialTranscription);
|
||||
_events.OnStateChange.RemoveListener(HandleStateChange);
|
||||
_events.OnStartListening.RemoveListener(HandleStartListening);
|
||||
_events.OnStopListening.RemoveListener(HandleStopListening);
|
||||
_events.OnDownloadProgressChange.RemoveListener(HandleDownloadProgressChange);
|
||||
_events.OnUploadProgressChange.RemoveListener(HandleUploadProgressChange);
|
||||
_events.OnAudioInputStateChange.RemoveListener(HandleAudioInputStateChange);
|
||||
}
|
||||
|
||||
private void HandleAudioInputStateChange(VoiceServiceRequest request)
|
||||
{
|
||||
SendMessage("OnAudioInputStateChange", request, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
private void HandleUploadProgressChange(VoiceServiceRequest request)
|
||||
{
|
||||
SendMessage("OnUploadProgressChange", request, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
private void HandleDownloadProgressChange(VoiceServiceRequest request)
|
||||
{
|
||||
SendMessage("OnDownloadProgressChange", request, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
private void HandleStopListening(VoiceServiceRequest request)
|
||||
{
|
||||
SendMessage("OnStopListening", request, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
private void HandleStartListening(VoiceServiceRequest request)
|
||||
{
|
||||
SendMessage("OnStartListening", request, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
private void HandleStateChange(VoiceServiceRequest request)
|
||||
{
|
||||
SendMessage("OnStateChange", request, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
private void HandleFullTranscription(string transcription)
|
||||
{
|
||||
SendMessage("OnFullTranscription", transcription, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
private void HandlePartialTranscription(string transcription)
|
||||
{
|
||||
SendMessage("OnPartialTranscription", transcription, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
private void HandleAudioDeactivation(VoiceServiceRequest request)
|
||||
{
|
||||
SendMessage("OnAudioDeactivation", request, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
private void HandleAudioActivation(VoiceServiceRequest request)
|
||||
{
|
||||
SendMessage("OnAudioActivation", request, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
private void HandleSuccess(VoiceServiceRequest request)
|
||||
{
|
||||
SendMessage("OnSuccess", request, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
private void HandleSend(VoiceServiceRequest request)
|
||||
{
|
||||
SendMessage("OnSend", request, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
private void HandleInit(VoiceServiceRequest request)
|
||||
{
|
||||
SendMessage("OnInit", request, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
private void HandleFailed(VoiceServiceRequest request)
|
||||
{
|
||||
SendMessage("OnFailed", request, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
private void HandleComplete(VoiceServiceRequest request)
|
||||
{
|
||||
_voiceEvents?.OnComplete?.Invoke(request);
|
||||
SendMessage("OnComplete", request, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
private void HandleCancel(VoiceServiceRequest request)
|
||||
{
|
||||
_voiceEvents?.OnCanceled?.Invoke("");
|
||||
SendMessage("OnCancel", request, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
_activation = _voice.Activate(new WitRequestOptions(), _events);
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
{
|
||||
_activation.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fccf0c254a8b42d1bc0cd66655cda486
|
||||
timeCreated: 1678764830
|
||||
8
Assets/Oculus/Voice/Scripts/Runtime/UX.meta
Normal file
8
Assets/Oculus/Voice/Scripts/Runtime/UX.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7b45f55dceb7e4479879d6a3f9643c5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
151
Assets/Oculus/Voice/Scripts/Runtime/UX/VoiceActivationButton.cs
Normal file
151
Assets/Oculus/Voice/Scripts/Runtime/UX/VoiceActivationButton.cs
Normal file
@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Meta.WitAi;
|
||||
using Meta.WitAi.Requests;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Oculus.VoiceSDK.UX
|
||||
{
|
||||
[RequireComponent(typeof(Button))]
|
||||
public class VoiceActivationButton : MonoBehaviour
|
||||
{
|
||||
// The button to be observed
|
||||
private Button _button;
|
||||
// The button label to be adjusted with state
|
||||
private Text _buttonLabel;
|
||||
|
||||
[Tooltip("Reference to the current voice service")]
|
||||
[SerializeField] private VoiceService _voiceService;
|
||||
|
||||
[Tooltip("Text to be shown while the voice service is not active")]
|
||||
[SerializeField] private string _activateText = "Activate";
|
||||
[Tooltip("Whether to immediately send data to service or to wait for the audio threshold")]
|
||||
[SerializeField] private bool _activateImmediately = false;
|
||||
|
||||
[Tooltip("Text to be shown while the voice service is active")]
|
||||
[SerializeField] private string _deactivateText = "Deactivate";
|
||||
[Tooltip("Whether to immediately abort request activation on deactivate")]
|
||||
[SerializeField] private bool _deactivateAndAbort = false;
|
||||
|
||||
// Current request
|
||||
private VoiceServiceRequest _request;
|
||||
private bool _isActive = false;
|
||||
|
||||
// Get button & label
|
||||
private void Awake()
|
||||
{
|
||||
_buttonLabel = GetComponentInChildren<Text>();
|
||||
_button = GetComponent<Button>();
|
||||
if (_voiceService == null)
|
||||
{
|
||||
_voiceService = FindObjectOfType<VoiceService>();
|
||||
}
|
||||
}
|
||||
// Add click delegate
|
||||
private void OnEnable()
|
||||
{
|
||||
RefreshActive();
|
||||
if (_button != null)
|
||||
{
|
||||
_button.onClick.AddListener(OnClick);
|
||||
}
|
||||
}
|
||||
// Remove click delegate
|
||||
private void OnDisable()
|
||||
{
|
||||
_isActive = false;
|
||||
if (_button != null)
|
||||
{
|
||||
_button.onClick.RemoveListener(OnClick);
|
||||
}
|
||||
}
|
||||
|
||||
// On click, activate if not active & deactivate if active
|
||||
private void OnClick()
|
||||
{
|
||||
if (!_isActive)
|
||||
{
|
||||
Activate();
|
||||
}
|
||||
else
|
||||
{
|
||||
Deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
// Activate depending on settings
|
||||
private void Activate()
|
||||
{
|
||||
if (!_activateImmediately)
|
||||
{
|
||||
_request = _voiceService.Activate(GetRequestEvents());
|
||||
}
|
||||
else
|
||||
{
|
||||
_request = _voiceService.ActivateImmediately(GetRequestEvents());
|
||||
}
|
||||
}
|
||||
|
||||
// Deactivate depending on settings
|
||||
private void Deactivate()
|
||||
{
|
||||
if (!_deactivateAndAbort)
|
||||
{
|
||||
_request.DeactivateAudio();
|
||||
}
|
||||
else
|
||||
{
|
||||
_request.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
// Get events
|
||||
private VoiceServiceRequestEvents GetRequestEvents()
|
||||
{
|
||||
VoiceServiceRequestEvents events = new VoiceServiceRequestEvents();
|
||||
events.OnInit.AddListener(OnInit);
|
||||
events.OnComplete.AddListener(OnComplete);
|
||||
return events;
|
||||
}
|
||||
// Request initialized
|
||||
private void OnInit(VoiceServiceRequest request)
|
||||
{
|
||||
_isActive = true;
|
||||
RefreshActive();
|
||||
}
|
||||
// Request completed
|
||||
private void OnComplete(VoiceServiceRequest request)
|
||||
{
|
||||
_isActive = false;
|
||||
RefreshActive();
|
||||
}
|
||||
|
||||
// Refresh active text
|
||||
private void RefreshActive()
|
||||
{
|
||||
if (_buttonLabel != null)
|
||||
{
|
||||
_buttonLabel.text = _isActive ? _deactivateText : _activateText;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 172cb0882a19c114790c463ad582025d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Meta.WitAi;
|
||||
using Meta.WitAi.Json;
|
||||
using Meta.WitAi.Requests;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Oculus.VoiceSDK.UX
|
||||
{
|
||||
[RequireComponent(typeof(Text))] [ExecuteInEditMode]
|
||||
public class VoiceTranscriptionLabel : MonoBehaviour
|
||||
{
|
||||
// The label to be updated
|
||||
public Text Label
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_label == null)
|
||||
{
|
||||
_label = gameObject.GetComponent<Text>();
|
||||
}
|
||||
return _label;
|
||||
}
|
||||
}
|
||||
private Text _label;
|
||||
|
||||
[Header("Listen Settings")]
|
||||
[Tooltip("Various voice services to be observed")]
|
||||
[SerializeField] private VoiceService[] _voiceServices;
|
||||
[Tooltip("Text color while receiving text")]
|
||||
[SerializeField] private Color _transcriptionColor = Color.black;
|
||||
|
||||
[Header("Prompt Settings")]
|
||||
[Tooltip("Color to be used for prompt text")]
|
||||
[SerializeField] private Color _promptColor = new Color(0.2f, 0.2f, 0.2f);
|
||||
[Tooltip("Prompt text that displays while listening but prior to completion")]
|
||||
[SerializeField] private string _promptDefault = "Press activate to begin listening";
|
||||
[Tooltip("Prompt text that displays while listening but prior to completion")]
|
||||
[SerializeField] private string _promptListening = "Listening...";
|
||||
|
||||
[Header("Error Settings")]
|
||||
[Tooltip("Color to be used for error text")]
|
||||
[SerializeField] private Color _errorColor = new Color(0.8f, 0.2f, 0.2f);
|
||||
|
||||
// If none found, grab all voice services
|
||||
private void Awake()
|
||||
{
|
||||
if (_voiceServices == null || _voiceServices.Length == 0)
|
||||
{
|
||||
_voiceServices = FindObjectsOfType<VoiceService>();
|
||||
}
|
||||
}
|
||||
|
||||
// Add service delegates
|
||||
private void OnEnable()
|
||||
{
|
||||
if (_voiceServices != null)
|
||||
{
|
||||
foreach (var service in _voiceServices)
|
||||
{
|
||||
service.VoiceEvents.OnStartListening.AddListener(OnStartListening);
|
||||
service.VoiceEvents.OnPartialTranscription.AddListener(OnTranscriptionChange);
|
||||
service.VoiceEvents.OnFullTranscription.AddListener(OnTranscriptionChange);
|
||||
service.VoiceEvents.OnError.AddListener(OnError);
|
||||
service.VoiceEvents.OnComplete.AddListener(OnComplete);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Remove service delegates
|
||||
private void OnDisable()
|
||||
{
|
||||
if (_voiceServices != null)
|
||||
{
|
||||
foreach (var service in _voiceServices)
|
||||
{
|
||||
service.VoiceEvents.OnStartListening.RemoveListener(OnStartListening);
|
||||
service.VoiceEvents.OnPartialTranscription.RemoveListener(OnTranscriptionChange);
|
||||
service.VoiceEvents.OnFullTranscription.RemoveListener(OnTranscriptionChange);
|
||||
service.VoiceEvents.OnError.RemoveListener(OnError);
|
||||
service.VoiceEvents.OnComplete.RemoveListener(OnComplete);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// Refresh prompt
|
||||
private void Update()
|
||||
{
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
SetText(_promptDefault, _promptColor);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Set listening
|
||||
private void OnStartListening()
|
||||
{
|
||||
SetText(_promptListening, _promptColor);
|
||||
}
|
||||
// Set text change
|
||||
private void OnTranscriptionChange(string text)
|
||||
{
|
||||
SetText(text, _transcriptionColor);
|
||||
}
|
||||
// Apply error
|
||||
private void OnError(string status, string error)
|
||||
{
|
||||
SetText($"[{status}] {error}", _errorColor);
|
||||
}
|
||||
// If no text came through, show prompt
|
||||
private void OnComplete(VoiceServiceRequest request)
|
||||
{
|
||||
if (Label != null && string.Equals(Label?.text, _promptListening))
|
||||
{
|
||||
SetText(_promptDefault, _promptColor);
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh text
|
||||
private void SetText(string newText, Color newColor)
|
||||
{
|
||||
// Ignore if same
|
||||
if (Label == null || string.Equals(newText, Label.text) && newColor == Label.color)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply text & color
|
||||
_label.text = newText;
|
||||
_label.color = newColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d6b7f41315d58e4b84dde7885b2f192
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Oculus/Voice/Scripts/Runtime/Utilities.meta
Normal file
8
Assets/Oculus/Voice/Scripts/Runtime/Utilities.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6886b33e19626349aa58ba3ffcfe9da
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#if UNITY_ANDROID && !UNITY_2020_2_OR_NEWER
|
||||
#define MISSING_ANDROID_PERMISSION_CALLBACK
|
||||
#endif
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
#if UNITY_ANDROID
|
||||
using UnityEngine.Android;
|
||||
#endif
|
||||
#if MISSING_ANDROID_PERMISSION_CALLBACK
|
||||
using Meta.WitAi;
|
||||
#endif
|
||||
|
||||
namespace Oculus.VoiceSDK.Utilities
|
||||
{
|
||||
public static class MicPermissionsManager
|
||||
{
|
||||
public static bool HasMicPermission()
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
return Permission.HasUserAuthorizedPermission(Permission.Microphone);
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void RequestMicPermission(Action<string> permissionGrantedCallback = null)
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
if (HasMicPermission())
|
||||
{
|
||||
permissionGrantedCallback?.Invoke(Permission.Microphone);
|
||||
return;
|
||||
}
|
||||
#if MISSING_ANDROID_PERMISSION_CALLBACK
|
||||
Permission.RequestUserPermission(Permission.Microphone);
|
||||
CoroutineUtility.StartCoroutine(CheckPermissionGranted(permissionGrantedCallback));
|
||||
#else
|
||||
var callbacks = new PermissionCallbacks();
|
||||
callbacks.PermissionGranted += s => permissionGrantedCallback?.Invoke(s);
|
||||
Permission.RequestUserPermission(Permission.Microphone, callbacks);
|
||||
#endif
|
||||
#else
|
||||
permissionGrantedCallback?.Invoke("android.permission.RECORD_AUDIO");
|
||||
|
||||
// Do nothing for now, but eventually we may want to handle IOS/whatever permissions here, too.
|
||||
#endif
|
||||
}
|
||||
|
||||
#if MISSING_ANDROID_PERMISSION_CALLBACK
|
||||
private const int PERMISSION_CHECK_FRAMES = 3;
|
||||
private static IEnumerator CheckPermissionGranted(Action<string> permissionGrantedCallback)
|
||||
{
|
||||
// Exit immediately
|
||||
if (permissionGrantedCallback == null)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
// Wait specified amount of frames
|
||||
for (int i = 0; i < PERMISSION_CHECK_FRAMES; i++)
|
||||
{
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
// Successful
|
||||
if (HasMicPermission())
|
||||
{
|
||||
permissionGrantedCallback?.Invoke(Permission.Microphone);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2521d2c8c8225f4cb7349ab441608f3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
20
Assets/Oculus/Voice/Scripts/Runtime/VoiceSDK.Runtime.asmdef
Normal file
20
Assets/Oculus/Voice/Scripts/Runtime/VoiceSDK.Runtime.asmdef
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "VoiceSDK.Runtime",
|
||||
"references": [
|
||||
"GUID:a6b2b1f1f66ed4645a97660636b8683d",
|
||||
"GUID:a7c32ded21d3b9b42a71cdf39f2ed8da",
|
||||
"GUID:4504b1a6e0fdcc3498c30b266e4a63bf",
|
||||
"GUID:f02292e638368584080af0193f81ff5c",
|
||||
"GUID:1c28d8b71ced07540b7c271537363cc6",
|
||||
"GUID:8bbcefc153e1f1b4a98680670797dd16"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e545cc0678493234a9368f4e470c29e8
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
78
Assets/Oculus/Voice/Scripts/Runtime/VoiceSDKConstants.cs
Normal file
78
Assets/Oculus/Voice/Scripts/Runtime/VoiceSDKConstants.cs
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Text;
|
||||
using Meta.WitAi;
|
||||
using Meta.WitAi.Requests;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Voice
|
||||
{
|
||||
/// <summary>
|
||||
/// Script for obtaining Voice SDK specific
|
||||
/// constants, including sdk version number.
|
||||
/// </summary>
|
||||
public static class VoiceSDKConstants
|
||||
{
|
||||
// On first access, initialize
|
||||
static VoiceSDKConstants()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
// On load, initialize
|
||||
[RuntimeInitializeOnLoadMethod]
|
||||
static void Init()
|
||||
{
|
||||
if (_isInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_isInitialized = true;
|
||||
WitVRequest.OnProvideCustomUserAgent += OnCustomUserAgent;
|
||||
}
|
||||
private static bool _isInitialized = false;
|
||||
|
||||
// Current Voice SDK Version
|
||||
public static string SdkVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_sdkVersion))
|
||||
{
|
||||
_sdkVersion = WitConstants.SDK_VERSION;
|
||||
}
|
||||
return _sdkVersion;
|
||||
}
|
||||
}
|
||||
// Overridden by build process
|
||||
private static string _sdkVersion = "57.0.0.193.153";
|
||||
|
||||
// User agent prefix
|
||||
private const string _userAgentPrefix = "voice-sdk-";
|
||||
// Append voice sdk if possible
|
||||
private static void OnCustomUserAgent(StringBuilder sb)
|
||||
{
|
||||
if (!sb.ToString().StartsWith(_userAgentPrefix))
|
||||
{
|
||||
sb.Insert(0, $"{_userAgentPrefix}{SdkVersion},");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e004e2206f7b45a4abcb75148bcccbd8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user