init
This commit is contained in:
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,161 @@
|
||||
/*
|
||||
* 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.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
|
||||
{
|
||||
// TODO: Fix VoiceSDKImpl to work with IVoiceRequest
|
||||
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 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 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)
|
||||
{
|
||||
eventBinding.VoiceEvents.OnRequestOptionSetup?.Invoke(requestOptions);
|
||||
service.Activate(text, requestOptions);
|
||||
return null;
|
||||
}
|
||||
|
||||
public VoiceServiceRequest Activate(WitRequestOptions requestOptions,
|
||||
VoiceServiceRequestEvents requestEvents)
|
||||
{
|
||||
if (_isActive) return null;
|
||||
_isActive = true;
|
||||
eventBinding.VoiceEvents.OnRequestOptionSetup?.Invoke(requestOptions);
|
||||
service.Activate(requestOptions);
|
||||
return null;
|
||||
}
|
||||
|
||||
public VoiceServiceRequest ActivateImmediately(WitRequestOptions requestOptions,
|
||||
VoiceServiceRequestEvents requestEvents)
|
||||
{
|
||||
if (_isActive) return null;
|
||||
_isActive = true;
|
||||
eventBinding.VoiceEvents.OnRequestOptionSetup?.Invoke(requestOptions);
|
||||
service.ActivateImmediately(requestOptions);
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
{
|
||||
_isActive = false;
|
||||
service.Deactivate();
|
||||
}
|
||||
|
||||
public void DeactivateAndAbortRequest()
|
||||
{
|
||||
_isActive = false;
|
||||
service.Deactivate();
|
||||
}
|
||||
|
||||
public void DeactivateAndAbortRequest(VoiceServiceRequest request)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3943048f6aa4a49977131e8fb7f677d
|
||||
timeCreated: 1630370598
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* 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.Events;
|
||||
using Meta.WitAi.Json;
|
||||
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;
|
||||
}
|
||||
|
||||
public void onResponse(string responseJson)
|
||||
{
|
||||
WitResponseNode responseData = WitResponseNode.Parse(responseJson);
|
||||
if (responseData != null)
|
||||
{
|
||||
VoiceEvents.OnResponse?.Invoke(responseData);
|
||||
}
|
||||
}
|
||||
|
||||
public void onPartialResponse(string responseJson)
|
||||
{
|
||||
WitResponseNode responseData = WitResponseNode.Parse(responseJson);
|
||||
if (responseData != null && responseData.HasResponse())
|
||||
{
|
||||
VoiceEvents.OnPartialResponse?.Invoke(responseData);
|
||||
}
|
||||
}
|
||||
|
||||
public void onError(string error, string message, string errorBody)
|
||||
{
|
||||
VoiceEvents.OnError?.Invoke(error, message);
|
||||
}
|
||||
|
||||
public void onAborted()
|
||||
{
|
||||
VoiceEvents.OnAborted?.Invoke();
|
||||
}
|
||||
|
||||
public void onRequestCompleted()
|
||||
{
|
||||
VoiceEvents.OnRequestCompleted?.Invoke();
|
||||
}
|
||||
|
||||
public void onMicLevelChanged(float level)
|
||||
{
|
||||
VoiceEvents.OnMicLevelChanged?.Invoke(level);
|
||||
}
|
||||
|
||||
public void onRequestCreated()
|
||||
{
|
||||
#pragma warning disable CS0618
|
||||
VoiceEvents.OnRequestCreated?.Invoke(null);
|
||||
VoiceEvents.OnSend?.Invoke(null);
|
||||
}
|
||||
|
||||
public void onStartListening()
|
||||
{
|
||||
VoiceEvents.OnStartListening?.Invoke();
|
||||
}
|
||||
|
||||
public void onStoppedListening(int reason)
|
||||
{
|
||||
VoiceEvents.OnStoppedListening?.Invoke();
|
||||
switch((StoppedListeningReason)reason){
|
||||
case StoppedListeningReason.NoReasonProvided:
|
||||
break;
|
||||
case StoppedListeningReason.Inactivity:
|
||||
VoiceEvents.OnStoppedListeningDueToInactivity?.Invoke();
|
||||
break;
|
||||
case StoppedListeningReason.Timeout:
|
||||
VoiceEvents.OnStoppedListeningDueToTimeout?.Invoke();
|
||||
break;
|
||||
case StoppedListeningReason.Deactivation:
|
||||
VoiceEvents.OnStoppedListeningDueToDeactivation?.Invoke();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void onMicDataSent()
|
||||
{
|
||||
VoiceEvents.OnMicDataSent?.Invoke();
|
||||
}
|
||||
|
||||
public void onMinimumWakeThresholdHit()
|
||||
{
|
||||
VoiceEvents.OnMinimumWakeThresholdHit?.Invoke();
|
||||
}
|
||||
|
||||
public void onPartialTranscription(string transcription)
|
||||
{
|
||||
VoiceEvents.OnPartialTranscription?.Invoke(transcription);
|
||||
}
|
||||
|
||||
public void onFullTranscription(string transcription)
|
||||
{
|
||||
VoiceEvents.OnFullTranscription?.Invoke(transcription);
|
||||
}
|
||||
|
||||
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/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,453 @@
|
||||
/*
|
||||
* 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;
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
// This version is auto-updated for a release build
|
||||
private readonly string PACKAGE_VERSION = "54.0.0.135.284";
|
||||
#endif
|
||||
|
||||
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 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() && voiceServiceImpl.CanSend();
|
||||
}
|
||||
|
||||
public override VoiceServiceRequest Activate(string text, WitRequestOptions requestOptions, VoiceServiceRequestEvents requestEvents)
|
||||
{
|
||||
if (CanSend())
|
||||
{
|
||||
voiceSDKLoggerImpl.LogInteractionStart(requestOptions.RequestId, "message");
|
||||
LogRequestConfig();
|
||||
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())
|
||||
{
|
||||
voiceSDKLoggerImpl.LogInteractionStart(requestOptions.RequestId, "speech");
|
||||
LogRequestConfig();
|
||||
return voiceServiceImpl.Activate(requestOptions, requestEvents);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override VoiceServiceRequest ActivateImmediately(WitRequestOptions requestOptions, VoiceServiceRequestEvents requestEvents)
|
||||
{
|
||||
if (CanActivateAudio() && CanSend())
|
||||
{
|
||||
voiceSDKLoggerImpl.LogInteractionStart(requestOptions.RequestId, "speech");
|
||||
LogRequestConfig();
|
||||
return voiceServiceImpl.ActivateImmediately(requestOptions, requestEvents);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void Deactivate()
|
||||
{
|
||||
voiceServiceImpl.Deactivate();
|
||||
}
|
||||
|
||||
public override void DeactivateAndAbortRequest()
|
||||
{
|
||||
voiceServiceImpl.DeactivateAndAbortRequest();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void InitVoiceSDK()
|
||||
{
|
||||
// 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
|
||||
|
||||
// Logging
|
||||
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;
|
||||
|
||||
// Logging
|
||||
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 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}");
|
||||
voiceSDKLoggerImpl.LogInteractionEndFailure(request.Results.Message);
|
||||
}
|
||||
else if (request.State == VoiceRequestState.Canceled)
|
||||
{
|
||||
VLog.W($"Request Canceled\nMessage: {request.Results.Message}");
|
||||
voiceSDKLoggerImpl.LogInteractionEndFailure("aborted");
|
||||
}
|
||||
else
|
||||
{
|
||||
VLog.D($"Request Success");
|
||||
voiceSDKLoggerImpl.LogInteractionEndSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
void LogRequestConfig()
|
||||
{
|
||||
#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));
|
||||
}
|
||||
#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/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",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:a6b2b1f1f66ed4645a97660636b8683d",
|
||||
"GUID:a7c32ded21d3b9b42a71cdf39f2ed8da",
|
||||
"GUID:4504b1a6e0fdcc3498c30b266e4a63bf",
|
||||
"GUID:f02292e638368584080af0193f81ff5c",
|
||||
"GUID:1c28d8b71ced07540b7c271537363cc6"
|
||||
],
|
||||
"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:
|
||||
Reference in New Issue
Block a user