Skip to content

Instantly share code, notes, and snippets.

@FreakTheMighty
Last active February 23, 2017 19:22
Show Gist options
  • Save FreakTheMighty/b49a75416d6d2cec1806326c0820b218 to your computer and use it in GitHub Desktop.
Save FreakTheMighty/b49a75416d6d2cec1806326c0820b218 to your computer and use it in GitHub Desktop.
HoloLens Text to Speech Logger
using HoloToolkit.Unity;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LogToSpeech : MonoBehaviour {
private TextToSpeechManager textToSpeech;
private Queue<string> logs = new Queue<string>();
void Start () {
textToSpeech = GetComponent<TextToSpeechManager>();
}
void Update()
{
StartCoroutine(ReadLogs());
}
IEnumerator ReadLogs()
{
if (logs.Count > 0 && textToSpeech.IsSpeaking() == false)
{
string text = logs.Dequeue();
textToSpeech.SpeakText(text);
}
yield return null;
}
void OnEnable()
{
Application.logMessageReceived += HandleLog;
}
void OnDisable()
{
Application.logMessageReceived -= HandleLog;
}
void HandleLog(string logString, string stackTrace, LogType type)
{
if (type == LogType.Log)
{
logs.Enqueue(logString);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment