init
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64b5e4399ce1894409af2cf7dcab6365
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7913ff34317620543add7ccf91153f48
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "Facebook.Wit.Dictation.Editor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:910a956078d2ff4429c717211dcfaecb",
|
||||
"GUID:fa958eb9f0171754fb207d563a15ddfa"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8a301fcccd2a404a9820dc1e9c0d5c3
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce420a201d5144a44b4c15f1b9c4cff5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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.Events.Editor;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Meta.WitAi.Dictation.Events.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(DictationEvents))]
|
||||
public class DictationEventPropertyDrawer : EventPropertyDrawer<DictationEvents>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b8f297a827717846a390137480216b9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7000a4548ba72474f9222567d06a50fc
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 110ee5aeb672b914bbc92f92061bcbd4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f0c2fb9674b409c869f53df88912235
|
||||
timeCreated: 1657568993
|
||||
@@ -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 System;
|
||||
using Meta.WitAi.Data;
|
||||
|
||||
namespace Meta.WitAi.Dictation.Data
|
||||
{
|
||||
[Serializable]
|
||||
public class DictationSession : VoiceSession
|
||||
{
|
||||
/// <summary>
|
||||
/// Dictation service being used
|
||||
/// </summary>
|
||||
public IDictationService dictationService;
|
||||
/// <summary>
|
||||
/// Collection of Request IDs generated from client for Wit requests
|
||||
/// </summary>
|
||||
public string[] clientRequestId;
|
||||
/// <summary>
|
||||
/// An identifier for the current dictation session
|
||||
/// </summary>
|
||||
public string sessionId = Guid.NewGuid().ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9809a25e34ab45d6a522b8f43e4c3703
|
||||
timeCreated: 1657569002
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* 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.Dictation.Events;
|
||||
using Meta.WitAi.Events;
|
||||
using Meta.WitAi.Events.UnityEventListeners;
|
||||
using Meta.WitAi.Interfaces;
|
||||
using Meta.WitAi.Requests;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Meta.WitAi.Dictation
|
||||
{
|
||||
public abstract class DictationService : MonoBehaviour, IDictationService, IAudioEventProvider, ITranscriptionEventProvider
|
||||
{
|
||||
[Tooltip("Events that will fire before, during and after an activation")]
|
||||
[SerializeField] protected DictationEvents dictationEvents = new DictationEvents();
|
||||
|
||||
///<summary>
|
||||
/// Internal events used to report telemetry. These events are reserved for internal
|
||||
/// use only and should not be used for any other purpose.
|
||||
/// </summary>
|
||||
protected TelemetryEvents telemetryEvents = new TelemetryEvents();
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if this voice service is currently active and listening with the mic
|
||||
/// </summary>
|
||||
public abstract bool Active { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the service is actively communicating with Wit.ai during an Activation. The mic may or may not still be active while this is true.
|
||||
/// </summary>
|
||||
public abstract bool IsRequestActive { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets a custom transcription provider. This can be used to replace any built in asr
|
||||
/// with an on device model or other provided source
|
||||
/// </summary>
|
||||
public abstract ITranscriptionProvider TranscriptionProvider { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if this voice service is currently reading data from the microphone
|
||||
/// </summary>
|
||||
public abstract bool MicActive { get; }
|
||||
|
||||
public virtual DictationEvents DictationEvents
|
||||
{
|
||||
get => dictationEvents;
|
||||
set => dictationEvents = value;
|
||||
}
|
||||
|
||||
public TelemetryEvents TelemetryEvents { get => telemetryEvents; set => telemetryEvents = value; }
|
||||
|
||||
/// <summary>
|
||||
/// A subset of events around collection of audio data
|
||||
/// </summary>
|
||||
public IAudioInputEvents AudioEvents => DictationEvents;
|
||||
|
||||
/// <summary>
|
||||
/// A subset of events around receiving transcriptions
|
||||
/// </summary>
|
||||
public ITranscriptionEvent TranscriptionEvents => DictationEvents;
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the audio input should be read in an activation
|
||||
/// </summary>
|
||||
protected abstract bool ShouldSendMicData { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Activate the microphone and send data for NLU processing. Includes optional additional request parameters like dynamic entities and maximum results.
|
||||
/// </summary>
|
||||
public void Activate() => Activate(new WitRequestOptions(), new VoiceServiceRequestEvents());
|
||||
/// <summary>
|
||||
/// Activate the microphone and send data for NLU processing. Includes optional additional request parameters like dynamic entities and maximum results.
|
||||
/// </summary>
|
||||
/// <param name="requestOptions">Additional options such as custom request id</param>
|
||||
public void Activate(WitRequestOptions requestOptions) => Activate(requestOptions, new VoiceServiceRequestEvents());
|
||||
/// <summary>
|
||||
/// Activate the microphone and send data for NLU processing. Includes optional additional request parameters like dynamic entities and maximum results.
|
||||
/// </summary>
|
||||
/// <param name="requestOptions">Additional options such as custom request id</param>
|
||||
public VoiceServiceRequest Activate(VoiceServiceRequestEvents requestEvents) => Activate(new WitRequestOptions(), requestEvents);
|
||||
/// <summary>
|
||||
/// Activate the microphone and send data for NLU processing. Includes optional additional request parameters like dynamic entities and maximum results.
|
||||
/// </summary>
|
||||
/// <param name="requestOptions">Additional options such as custom request id</param>
|
||||
/// <param name="requestEvents">Events specific to the request's lifecycle</param>
|
||||
public abstract VoiceServiceRequest Activate(WitRequestOptions requestOptions, VoiceServiceRequestEvents requestEvents);
|
||||
|
||||
/// <summary>
|
||||
/// Activate the microphone and send data for NLU processing immediately without waiting for sound/speech from the user to begin. Includes optional additional request parameters like dynamic entities and maximum results.
|
||||
/// </summary>
|
||||
public void ActivateImmediately() => ActivateImmediately(new WitRequestOptions(), new VoiceServiceRequestEvents());
|
||||
/// <summary>
|
||||
/// Activate the microphone and send data for NLU processing immediately without waiting for sound/speech from the user to begin. Includes optional additional request parameters like dynamic entities and maximum results.
|
||||
/// </summary>
|
||||
/// <param name="requestOptions">Additional options such as custom request id</param>
|
||||
public void ActivateImmediately(WitRequestOptions requestOptions) => ActivateImmediately(requestOptions, new VoiceServiceRequestEvents());
|
||||
/// <summary>
|
||||
/// Activate the microphone and send data for NLU processing immediately without waiting for sound/speech from the user to begin. Includes optional additional request parameters like dynamic entities and maximum results.
|
||||
/// </summary>
|
||||
/// <param name="requestOptions">Additional options such as custom request id</param>
|
||||
public VoiceServiceRequest ActivateImmediately(VoiceServiceRequestEvents requestEvents) => ActivateImmediately(new WitRequestOptions(), requestEvents);
|
||||
/// <summary>
|
||||
/// Activate the microphone and send data for NLU processing immediately without waiting for sound/speech from the user to begin. Includes optional additional request parameters like dynamic entities and maximum results.
|
||||
/// </summary>
|
||||
/// <param name="requestOptions">Additional options such as custom request id</param>
|
||||
/// <param name="requestEvents">Events specific to the request's lifecycle</param>
|
||||
public abstract VoiceServiceRequest ActivateImmediately(WitRequestOptions requestOptions, VoiceServiceRequestEvents requestEvents);
|
||||
|
||||
/// <summary>
|
||||
/// Stop listening and submit any remaining buffered microphone data for processing.
|
||||
/// </summary>
|
||||
public abstract void Deactivate();
|
||||
|
||||
/// <summary>
|
||||
/// Cancels the current transcription. No FullTranscription event will fire.
|
||||
/// </summary>
|
||||
public abstract void Cancel();
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
var audioEventListener = GetComponent<AudioEventListener>();
|
||||
if (!audioEventListener)
|
||||
{
|
||||
gameObject.AddComponent<AudioEventListener>();
|
||||
}
|
||||
|
||||
var transcriptionEventListener = GetComponent<TranscriptionEventListener>();
|
||||
if (!transcriptionEventListener)
|
||||
{
|
||||
gameObject.AddComponent<TranscriptionEventListener>();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public interface IDictationService: ITelemetryEventsProvider
|
||||
{
|
||||
bool Active { get; }
|
||||
|
||||
bool IsRequestActive { get; }
|
||||
|
||||
bool MicActive { get; }
|
||||
|
||||
ITranscriptionProvider TranscriptionProvider { get; set; }
|
||||
|
||||
DictationEvents DictationEvents { get; set; }
|
||||
|
||||
new TelemetryEvents TelemetryEvents { get; set; }
|
||||
|
||||
VoiceServiceRequest Activate(WitRequestOptions requestOptions, VoiceServiceRequestEvents requestEvents);
|
||||
|
||||
VoiceServiceRequest ActivateImmediately(WitRequestOptions requestOptions, VoiceServiceRequestEvents requestEvents);
|
||||
|
||||
void Deactivate();
|
||||
|
||||
void Cancel();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d481126888a4412939f6940b2fa3950
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b23994c7bbf9462ca7b6939d3d364e7c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using Meta.WitAi.Events;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace Meta.WitAi.Dictation.Events
|
||||
{
|
||||
[Serializable]
|
||||
public class DictationEvents : SpeechEvents
|
||||
{
|
||||
private const string EVENT_CATEGORY_DICTATION_EVENTS = "Dictation Events";
|
||||
|
||||
/// <summary>
|
||||
/// Called when an individual dictation session has started. This can include multiple server activations if
|
||||
/// dictation is set up to automatically reactivate when the server endpoints an utterance.
|
||||
/// </summary>
|
||||
[Tooltip("Called when an individual dictation session has started. This can include multiple server activations if dictation is set up to automatically reactivate when the server endpoints an utterance.")]
|
||||
[EventCategory(EVENT_CATEGORY_DICTATION_EVENTS)]
|
||||
[FormerlySerializedAs("onDictationSessionStarted")] [SerializeField] [HideInInspector]
|
||||
private DictationSessionEvent _onDictationSessionStarted = new DictationSessionEvent();
|
||||
public DictationSessionEvent OnDictationSessionStarted => _onDictationSessionStarted;
|
||||
|
||||
/// <summary>
|
||||
/// Called when a dictation is completed after Deactivate has been called or auto-reactivate is disabled.
|
||||
/// </summary>
|
||||
[Tooltip("Called when a dictation is completed after Deactivate has been called or auto-reactivate is disabled.")]
|
||||
[EventCategory(EVENT_CATEGORY_DICTATION_EVENTS)]
|
||||
[FormerlySerializedAs("onDictationSessionStopped")] [SerializeField] [HideInInspector]
|
||||
private DictationSessionEvent _onDictationSessionStopped = new DictationSessionEvent();
|
||||
public DictationSessionEvent OnDictationSessionStopped => _onDictationSessionStopped;
|
||||
|
||||
// Deprecated events
|
||||
[Obsolete("Deprecated for 'OnDictationSessionStarted' event")]
|
||||
public DictationSessionEvent onDictationSessionStarted => OnDictationSessionStarted;
|
||||
[Obsolete("Deprecated for 'OnDictationSessionStopped' event")]
|
||||
public DictationSessionEvent onDictationSessionStopped => OnDictationSessionStopped;
|
||||
[Obsolete("Deprecated for 'OnStartListening' event")]
|
||||
public UnityEvent onStart => OnStartListening;
|
||||
[Obsolete("Deprecated for 'OnStoppedListening' event")]
|
||||
public UnityEvent onStopped => OnStoppedListening;
|
||||
[Obsolete("Deprecated for 'OnMicLevelChanged' event")]
|
||||
public WitMicLevelChangedEvent onMicAudioLevel => OnMicLevelChanged;
|
||||
[Obsolete("Deprecated for 'OnError' event")]
|
||||
public WitErrorEvent onError => OnError;
|
||||
[Obsolete("Deprecated for 'OnResponse' event")]
|
||||
public WitResponseEvent onResponse => OnResponse;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 866a0a2cd26dd0c469bb96bf7be7ec27
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using Meta.WitAi.Dictation.Data;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Meta.WitAi.Dictation.Events
|
||||
{
|
||||
[Serializable]
|
||||
public class DictationSessionEvent : UnityEvent<DictationSession>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8d63aebd47343999a855f5eff93e7a2
|
||||
timeCreated: 1657570491
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "Facebook.Wit.Dictation",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:1c28d8b71ced07540b7c271537363cc6",
|
||||
"GUID:4504b1a6e0fdcc3498c30b266e4a63bf"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 910a956078d2ff4429c717211dcfaecb
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using Meta.WitAi.Events;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Meta.WitAi.Dictation
|
||||
{
|
||||
public class MultiRequestTranscription : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private WitDictation witDictation;
|
||||
[SerializeField] private int linesBetweenActivations = 2;
|
||||
[Multiline]
|
||||
[SerializeField] private string activationSeparator = String.Empty;
|
||||
|
||||
[Header("Events")]
|
||||
[SerializeField] private WitTranscriptionEvent onTranscriptionUpdated = new
|
||||
WitTranscriptionEvent();
|
||||
|
||||
private StringBuilder _text;
|
||||
private string _activeText;
|
||||
private bool _newSection;
|
||||
|
||||
private StringBuilder _separator;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (!witDictation) witDictation = FindObjectOfType<WitDictation>();
|
||||
|
||||
_text = new StringBuilder();
|
||||
_separator = new StringBuilder();
|
||||
for (int i = 0; i < linesBetweenActivations; i++)
|
||||
{
|
||||
_separator.AppendLine();
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(activationSeparator))
|
||||
{
|
||||
_separator.Append(activationSeparator);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
witDictation.VoiceEvents.OnFullTranscription.AddListener(OnFullTranscription);
|
||||
witDictation.VoiceEvents.OnPartialTranscription.AddListener(OnPartialTranscription);
|
||||
witDictation.VoiceEvents.OnAborting.AddListener(OnCancelled);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_activeText = string.Empty;
|
||||
witDictation.VoiceEvents.OnFullTranscription.RemoveListener(OnFullTranscription);
|
||||
witDictation.VoiceEvents.OnPartialTranscription.RemoveListener(OnPartialTranscription);
|
||||
}
|
||||
|
||||
private void OnCancelled()
|
||||
{
|
||||
_activeText = string.Empty;
|
||||
OnTranscriptionUpdated();
|
||||
}
|
||||
|
||||
private void OnFullTranscription(string text)
|
||||
{
|
||||
_activeText = string.Empty;
|
||||
|
||||
if (_text.Length > 0)
|
||||
{
|
||||
_text.Append(_separator);
|
||||
}
|
||||
|
||||
_text.Append(text);
|
||||
|
||||
OnTranscriptionUpdated();
|
||||
}
|
||||
|
||||
private void OnPartialTranscription(string text)
|
||||
{
|
||||
_activeText = text;
|
||||
OnTranscriptionUpdated();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_text.Clear();
|
||||
onTranscriptionUpdated.Invoke(string.Empty);
|
||||
}
|
||||
|
||||
private void OnTranscriptionUpdated()
|
||||
{
|
||||
var transcription = new StringBuilder();
|
||||
transcription.Append(_text);
|
||||
if (!string.IsNullOrEmpty(_activeText))
|
||||
{
|
||||
if (transcription.Length > 0)
|
||||
{
|
||||
transcription.Append(_separator);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(_activeText))
|
||||
{
|
||||
transcription.Append(_activeText);
|
||||
}
|
||||
}
|
||||
|
||||
onTranscriptionUpdated.Invoke(transcription.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a960272debaf35b4f8df9292e4191044
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e507c9f16a2497a940845bf47606a99
|
||||
timeCreated: 1656528581
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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.Interfaces;
|
||||
using Meta.WitAi.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Meta.WitAi.ServiceReferences
|
||||
{
|
||||
public class DictationServiceAudioEventReference : AudioInputServiceReference
|
||||
{
|
||||
[SerializeField] private DictationServiceReference _dictationServiceReference;
|
||||
|
||||
public override IAudioInputEvents AudioEvents =>
|
||||
_dictationServiceReference.DictationService.AudioEvents;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2029a881fa07405c941899ca44707e0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using Meta.WitAi.Dictation;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace Meta.WitAi.Utilities
|
||||
{
|
||||
[Serializable]
|
||||
public struct DictationServiceReference
|
||||
{
|
||||
[SerializeField] internal DictationService dictationService;
|
||||
|
||||
public DictationService DictationService
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!dictationService)
|
||||
{
|
||||
DictationService[] services = Resources.FindObjectsOfTypeAll<DictationService>();
|
||||
if (services != null)
|
||||
{
|
||||
// Set as first instance that isn't a prefab
|
||||
dictationService = Array.Find(services, (o) => o.gameObject.scene.rootCount != 0);
|
||||
}
|
||||
}
|
||||
|
||||
return dictationService;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[CustomPropertyDrawer(typeof(DictationServiceReference))]
|
||||
public class DictationServiceReferenceDrawer : PropertyDrawer
|
||||
{
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight;
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var refProp = property.FindPropertyRelative("DictationService");
|
||||
var reference = refProp.objectReferenceValue as DictationService;
|
||||
var dictationServices = GameObject.FindObjectsOfType<DictationService>();
|
||||
var dictationServiceNames = new string[dictationServices.Length + 1];
|
||||
int index = 0;
|
||||
dictationServiceNames[0] = "Autodetect";
|
||||
if (dictationServices.Length == 1)
|
||||
{
|
||||
dictationServiceNames[0] = $"{dictationServiceNames[0]} - {dictationServices[0].name}";
|
||||
}
|
||||
for (int i = 0; i < dictationServices.Length; i++)
|
||||
{
|
||||
dictationServiceNames[i + 1] = dictationServices[i].name;
|
||||
if (dictationServices[i] == reference)
|
||||
{
|
||||
index = i + 1;
|
||||
}
|
||||
}
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
var updatedIndex = EditorGUI.Popup(position, index, dictationServiceNames);
|
||||
if (index != updatedIndex)
|
||||
{
|
||||
if (updatedIndex > 0)
|
||||
{
|
||||
refProp.objectReferenceValue = dictationServices[updatedIndex - 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
refProp.objectReferenceValue = null;
|
||||
}
|
||||
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a487e94faee3e430989a08cd6d770e3d
|
||||
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.
|
||||
*
|
||||
* This source code is licensed under the license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
using System.IO;
|
||||
using Meta.WitAi.Configuration;
|
||||
using Meta.WitAi.Data.Configuration;
|
||||
using Meta.WitAi.Dictation.Events;
|
||||
using Meta.WitAi.Events;
|
||||
using Meta.WitAi.Interfaces;
|
||||
using Meta.WitAi.Requests;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Meta.WitAi.Dictation
|
||||
{
|
||||
public class WitDictation : DictationService, IWitRuntimeConfigProvider, IVoiceEventProvider, IWitRequestProvider, IWitConfigurationProvider
|
||||
{
|
||||
[SerializeField] private WitRuntimeConfiguration witRuntimeConfiguration;
|
||||
|
||||
private WitService witService;
|
||||
|
||||
public WitRuntimeConfiguration RuntimeConfiguration
|
||||
{
|
||||
get => witRuntimeConfiguration;
|
||||
set => witRuntimeConfiguration = value;
|
||||
}
|
||||
public WitConfiguration Configuration => RuntimeConfiguration?.witConfiguration;
|
||||
|
||||
#region Voice Service Properties
|
||||
|
||||
public override bool Active => null != witService && witService.Active;
|
||||
public override bool IsRequestActive => null != witService && witService.IsRequestActive;
|
||||
|
||||
public override ITranscriptionProvider TranscriptionProvider
|
||||
{
|
||||
get => witService.TranscriptionProvider;
|
||||
set => witService.TranscriptionProvider = value;
|
||||
|
||||
}
|
||||
|
||||
public override bool MicActive => null != witService && witService.MicActive;
|
||||
|
||||
protected override bool ShouldSendMicData => witRuntimeConfiguration.sendAudioToWit ||
|
||||
null == TranscriptionProvider;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Events specific to wit voice activation.
|
||||
/// </summary>
|
||||
public VoiceEvents VoiceEvents => _voiceEvents;
|
||||
private readonly VoiceEvents _voiceEvents = new VoiceEvents();
|
||||
|
||||
public override DictationEvents DictationEvents
|
||||
{
|
||||
get => dictationEvents;
|
||||
set
|
||||
{
|
||||
DictationEvents oldEvents = dictationEvents;
|
||||
dictationEvents = value;
|
||||
if (gameObject.activeSelf)
|
||||
{
|
||||
VoiceEvents.RemoveListener(oldEvents);
|
||||
VoiceEvents.AddListener(dictationEvents);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IWitRequestProvider
|
||||
public WitRequest CreateWitRequest(WitConfiguration config, WitRequestOptions requestOptions,
|
||||
VoiceServiceRequestEvents requestEvents,
|
||||
IDynamicEntitiesProvider[] additionalEntityProviders = null)
|
||||
{
|
||||
return config.CreateDictationRequest(requestOptions, requestEvents);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Voice Service Methods
|
||||
/// <summary>
|
||||
/// Activates and waits for the user to exceed the min wake threshold before data is sent to the server.
|
||||
/// </summary>
|
||||
/// <param name="requestOptions">Additional options such as custom request id</param>
|
||||
/// <param name="requestEvents">Events specific to the request's lifecycle</param>
|
||||
public override VoiceServiceRequest Activate(WitRequestOptions requestOptions, VoiceServiceRequestEvents requestEvents)
|
||||
{
|
||||
return witService.Activate(requestOptions, requestEvents);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Activates immediately and starts sending data to the server. This will not wait for min wake threshold
|
||||
/// </summary>
|
||||
/// <param name="requestOptions">Additional options such as custom request id</param>
|
||||
/// <param name="requestEvents">Events specific to the request's lifecycle</param>
|
||||
public override VoiceServiceRequest ActivateImmediately(WitRequestOptions requestOptions, VoiceServiceRequestEvents requestEvents)
|
||||
{
|
||||
return witService.ActivateImmediately(requestOptions, requestEvents);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deactivates. If a transcription is in progress the network request will complete and any additional
|
||||
/// transcription values will be returned.
|
||||
/// </summary>
|
||||
public override void Deactivate()
|
||||
{
|
||||
witService.Deactivate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deactivates and ignores any pending transcription content.
|
||||
/// </summary>
|
||||
public override void Cancel()
|
||||
{
|
||||
witService.DeactivateAndAbortRequest();
|
||||
}
|
||||
#endregion
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
witService = gameObject.AddComponent<WitService>();
|
||||
witService.VoiceEventProvider = this;
|
||||
witService.ConfigurationProvider = this;
|
||||
witService.WitRequestProvider = this;
|
||||
witService.TelemetryEventsProvider = this;
|
||||
}
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
VoiceEvents.AddListener(DictationEvents);
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
VoiceEvents.RemoveListener(DictationEvents);
|
||||
}
|
||||
|
||||
public void TranscribeFile(string fileName)
|
||||
{
|
||||
var request = CreateWitRequest(witRuntimeConfiguration.witConfiguration, new WitRequestOptions(), new VoiceServiceRequestEvents());
|
||||
var data = File.ReadAllBytes(fileName);
|
||||
request.postData = data;
|
||||
witService.ExecuteRequest(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4398589986ec92e46a7e1585e63ff2a5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user