Commit 23cdeab2 authored by Ben Huber's avatar Ben Huber
Browse files

language select in demo scene

parent a4a56f6e
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ButtonScript : MonoBehaviour {
public InputField input;
public void OnBtnPressed() {
PurpleSloth.TextToSpeech.Say(input.text);
input.text = "";
foreach (var v in PurpleSloth.TextToSpeech.AvailableVoices()) {
Debug.Log(v);
input.text += v;
}
}
}
......@@ -27,8 +27,13 @@ mergeInto(LibraryManager.library, {
ans = "";
for(i = 0; i < voices.length ; i++) {
ans += voices[i].name + ' (' + voices[i].lang + ');';
ans += voices[i].name + ' (' + voices[i].lang + ')';
if (voices[i].default) {
ans += ' [default]';
}
ans += ';';
}
ans = ans.substring(0, ans.length-1);
var bufferSize = lengthBytesUTF8(ans) + 1;
var buffer = _malloc(bufferSize);
......
fileFormatVersion: 2
guid: 39ec677b905ffc8fba14341080fee380
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: a483ece5b0dac0179b7001be19d0b5c6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ButtonScript : MonoBehaviour {
public InputField inputText;
public InputField inputLang;
public InputField inputRate;
public InputField inputPitch;
public Dropdown voiceSelection;
private void Awake() {
inputLang.text = "en-US";
inputRate.text = "1.0";
inputPitch.text = "1.0";
}
public void OnBtnPressed() {
// transfer options from input fields to TTS settings
PurpleSloth.TextToSpeech.language = inputLang.text;
PurpleSloth.TextToSpeech.pitch = float.Parse(inputPitch.text);
PurpleSloth.TextToSpeech.rate = float.Parse(inputRate.text);
if (voiceSelection.options.Count == 0) {
// if we have no initialized voice list yet simply use the default voice
PurpleSloth.TextToSpeech.Say(inputText.text);
} else {
PurpleSloth.TextToSpeech.Say(inputText.text, voiceSelection.value);
}
}
}
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
public class FillVoicesList : MonoBehaviour {
void Update() {
// we don't know exactly when the browser fills the list of available voices
// so we simply request it until we receive a non-empty result
var voices = PurpleSloth.TextToSpeech.AvailableVoices();
if (voices.Length == 0) return;
Dropdown list = GetComponent<Dropdown>();
list.AddOptions(voices.Select(v => new Dropdown.OptionData(v)).ToList());
this.enabled = false; // no need to execute this script anymore
}
}
fileFormatVersion: 2
guid: 2b2012dc0e1eac6728750ecd6a273b58
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
......@@ -6,6 +6,6 @@ EditorBuildSettings:
serializedVersion: 2
m_Scenes:
- enabled: 1
path: Assets/PurpleSloth/SampleScene.unity
path: Assets/PurpleSloth/Demo/SampleScene.unity
guid: 2cda990e2423bbf4892e6590ba056729
m_configObjects: {}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment