init
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user