Commit a4a56f6e authored by Ben Huber's avatar Ben Huber

first TTS

parent fc3d2f44
Pipeline #1380 failed with stages
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;
}
}
}
fileFormatVersion: 2
guid: f24793aacd4e3aa72aee96ef624805a4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: a91ffb31522742c22aae7b64bb337c4b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 374cc23d454d089e5a18e24e3628f944
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 1579e34d98fabc3ea9baa92e34054224
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
mergeInto(LibraryManager.library, {
PpS_Speak: function (strPointer, langPtr, vol, r, p) {
var msg = new SpeechSynthesisUtterance(Pointer_stringify(strPointer));
msg.lang = Pointer_stringify(langPtr);
msg.volume = vol;
msg.rate = r;
msg.pitch = p;
window.speechSynthesis.cancel();// stop any TTS that may still be active
window.speechSynthesis.speak(msg);
},
PpS_SpeakVoiced: function (strPointer, langPtr, vol, r, p, voiceIdx) {
var msg = new SpeechSynthesisUtterance(Pointer_stringify(strPointer));
msg.lang = Pointer_stringify(langPtr);
msg.volume = vol;
msg.rate = r;
msg.pitch = p;
msg.voice = window.speechSynthesis.getVoices()[voiceIdx];
window.speechSynthesis.cancel();// stop any TTS that may still be active
window.speechSynthesis.speak(msg);
},
PpS_GetVoices: function () {
voices = window.speechSynthesis.getVoices();
ans = "";
for(i = 0; i < voices.length ; i++) {
ans += voices[i].name + ' (' + voices[i].lang + ');';
}
var bufferSize = lengthBytesUTF8(ans) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(ans, buffer, bufferSize);
return buffer;
}
});
fileFormatVersion: 2
guid: fab6f84abff6495e6b84e98aec488fd2
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Facebook: WebGL
second:
enabled: 1
settings: {}
- first:
WebGL: WebGL
second:
enabled: 1
settings: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: aa8c4765c50cb623eb1ce8c21acac154
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Linq;
using UnityEngine;
namespace PurpleSloth {
public class TextToSpeech {
// these methods are supplied by TextToSpeech.jslib in the plugins folder
[DllImport("__Internal")]
private static extern void PpS_Speak(string str, string lang, float vol, float r, float p);
[DllImport("__Internal")]
private static extern void PpS_SpeakVoiced(string str, string lang, float vol, float r, float p, int voiceIdx);
[DllImport("__Internal")]
private static extern string PpS_GetVoices();
// The language of the text to be spoken. Default: 'en-US'
public static string language = "en-US";
// Pitch modifier for the voice. Default 1; min 0; max 2
public static float pitch = 1f;
// Rate modifier. For example "rate = 2" means that the text is spoken twice as fast.
// default: 1; min: 0.1; max: 10
public static float rate = 1f;
// Volume of the speech. Default: 1; min: 0; max: 1
public static float volume = 1f; // 0 to 1
// Reads the text given. Cancels all text currently being spoken.
public static void Say(string text) {
if (Application.platform != RuntimePlatform.WebGLPlayer) {
Debug.LogWarning("Attempted to use PurpleSloth.TextToSpeech.Say(...) outside of a WebGL build. This is not supported.");
return;
}
PpS_Speak(text, language, volume, rate, pitch);
}
// Reads the text given in the named voice. Cancels all text currently being spoken.
public static void Say(string text, int voice) {
if (Application.platform != RuntimePlatform.WebGLPlayer) {
Debug.LogWarning("Attempted to use PurpleSloth.TextToSpeech.Say(...) outside of a WebGL build. This is not supported.");
return;
}
PpS_SpeakVoiced(text, language, volume, rate, pitch, voice);
}
// Returns a list of all available voices in the current browser.
// Note two things:
// 1. This list is not available from the beginning, so you may need to call this function another time if the returned list was empty.
// 2. You may need to change the voice simply to have correct pronunciation for different languages.
public static string[] AvailableVoices() {
if (Application.platform != RuntimePlatform.WebGLPlayer) {
Debug.LogWarning("Attempted to use PurpleSloth.TextToSpeech.AvailableVoices() outside of a WebGL build. This is not supported.");
return new string[0];
}
return PpS_GetVoices().Split(';').ToArray();
}
}
}
fileFormatVersion: 2
guid: 966910b07c55f7ba9bce20a53cb3e58b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 9
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 3
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 11
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_TemporalCoherenceThreshold: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 0
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 10
m_Resolution: 2
m_BakeResolution: 40
m_AtlasSize: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 0
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500
m_PVRBounces: 2
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVRFilteringMode: 1
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ShowResolutionOverlay: 1
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &519420028
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 519420032}
- component: {fileID: 519420031}
- component: {fileID: 519420029}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &519420029
AudioListener:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 519420028}
m_Enabled: 1
--- !u!20 &519420031
Camera:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 519420028}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 2
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 0
m_HDR: 1
m_AllowMSAA: 0
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 0
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!4 &519420032
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 519420028}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
......@@ -6,6 +6,6 @@ EditorBuildSettings:
serializedVersion: 2
m_Scenes:
- enabled: 1
path: Assets/Scenes/SampleScene.unity
path: Assets/PurpleSloth/SampleScene.unity
guid: 2cda990e2423bbf4892e6590ba056729
m_configObjects: {}
......@@ -31,6 +31,8 @@ GraphicsSettings:
m_AlwaysIncludedShaders:
- {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0}
......
......@@ -4,7 +4,7 @@
UnityConnectSettings:
m_ObjectHideFlags: 0
serializedVersion: 1
m_Enabled: 0
m_Enabled: 1
m_TestMode: 0
m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events
m_EventUrl: https://cdp.cloud.unity3d.com/v1/events
......
Markdown is supported
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