Last active
February 23, 2017 19:22
-
-
Save FreakTheMighty/b49a75416d6d2cec1806326c0820b218 to your computer and use it in GitHub Desktop.
HoloLens Text to Speech Logger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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