Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Added a base dictation handler
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHodgson committed Apr 5, 2019
1 parent 4c03fe4 commit 9858bd4
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
100 changes: 100 additions & 0 deletions Features/Input/Handlers/BaseDictationHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEngine;
using XRTK.EventDatum.Input;
using XRTK.Interfaces.InputSystem.Handlers;
using XRTK.Interfaces.Providers.Controllers;
using XRTK.Services;

namespace XRTK.SDK.Input.Handlers
{
/// <summary>
/// Script used to start and stop recording sessions in the current dictation system.
/// For this script to work, a dictation system like 'Windows Dictation Data Provider' must be added to the Data Providers in the Input System profile.
/// </summary>
public class BaseDictationHandler : BaseInputHandler, IMixedRealityDictationHandler
{
[SerializeField]
[Tooltip("Time length in seconds before the dictation session ends due to lack of audio input in case there was no audio heard in the current session")]
private float initialSilenceTimeout = 5f;

[SerializeField]
[Tooltip("Time length in seconds before the dictation session ends due to lack of audio input.")]
private float autoSilenceTimeout = 20f;

[SerializeField]
[Tooltip("Length in seconds for the dictation service to listen")]
private int recordingTime = 10;

[SerializeField]
[Tooltip("Whether recording should start automatically on start")]
private bool startRecordingOnStart = false;

private IMixedRealityDictationDataProvider dictationSystem;

/// <summary>
/// Start a recording session in the dictation system.
/// </summary>
public virtual void StartRecording()
{
dictationSystem?.StartRecording(gameObject, initialSilenceTimeout, autoSilenceTimeout, recordingTime);
}

/// <summary>
/// Stop a recording session in the dictation system.
/// </summary>
public virtual void StopRecording()
{
dictationSystem?.StopRecording();
}

#region MonoBehaviour implementation

protected override void Start()
{
base.Start();

dictationSystem = MixedRealityToolkit.GetService<IMixedRealityDictationDataProvider>();
Debug.Assert(dictationSystem != null, "No dictation system found. In order to use dictation, add a dictation system like 'Windows Dictation Input Provider' to the Data Providers in the Input System profile");

if (startRecordingOnStart)
{
StartRecording();
}
}

protected override void OnDisable()
{
StopRecording();

base.OnDisable();
}

#endregion MonoBehaviour implementation

#region IMixedRealityDictationHandler implementation

/// <inheritdoc />
public virtual void OnDictationHypothesis(DictationEventData eventData)
{
}

/// <inheritdoc />
public virtual void OnDictationResult(DictationEventData eventData)
{
}

/// <inheritdoc />
public virtual void OnDictationComplete(DictationEventData eventData)
{
}

/// <inheritdoc />
public virtual void OnDictationError(DictationEventData eventData)
{
}

#endregion IMixedRealityDictationHandler implementation
}
}
11 changes: 11 additions & 0 deletions Features/Input/Handlers/BaseDictationHandler.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9858bd4

Please sign in to comment.