Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed Assets/Piper/Plugins/Windows/espeak-ng.dll
Binary file not shown.
8 changes: 8 additions & 0 deletions Assets/Piper/Plugins/macOS.meta

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

Binary file not shown.

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

2 changes: 1 addition & 1 deletion Assets/Piper/Samples/PiperSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class PiperSample : MonoBehaviour

private AudioSource _source;

private void Awake()
private void Awake()
{
_source = GetComponent<AudioSource>();
input.onSubmit.AddListener(OnInputSubmit);
Expand Down
23 changes: 13 additions & 10 deletions Assets/Piper/Samples/PiperSample.unity
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ OcclusionCullingSettings:
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 9
serializedVersion: 10
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
Expand All @@ -38,13 +38,12 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 705507994}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 12
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
Expand All @@ -67,9 +66,6 @@ LightmapSettings:
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: 1
Expand Down Expand Up @@ -367,9 +363,8 @@ Light:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 705507993}
m_Enabled: 1
serializedVersion: 10
serializedVersion: 11
m_Type: 1
m_Shape: 0
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 1
m_Range: 10
Expand Down Expand Up @@ -419,8 +414,12 @@ Light:
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_UseViewFrustumForShadowCasterCull: 1
m_ForceVisible: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
m_LightUnit: 1
m_LuxAtDistance: 1
m_EnableSpotReflector: 1
--- !u!4 &705507995
Transform:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -639,6 +638,9 @@ MeshRenderer:
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
Expand Down Expand Up @@ -840,6 +842,7 @@ AudioSource:
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 0}
m_Resource: {fileID: 0}
m_PlayOnAwake: 0
m_Volume: 1
m_Pitch: 1
Expand Down Expand Up @@ -1159,9 +1162,9 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
backend: 512
model: {fileID: 5022602860645237092, guid: 808a451b47032994c9dc7906b4c27ec7, type: 3}
model: {fileID: 5022602860645237092, guid: 4e2afd77f290c4dd68adb6d86976ace9, type: 3}
voice: en-us
sampleRate: 22050
sampleRate: 16000
--- !u!1 &1795061063
GameObject:
m_ObjectHideFlags: 0
Expand Down
36 changes: 17 additions & 19 deletions Assets/Piper/Scripts/PiperManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Unity.Sentis;
using UnityEngine;
Expand All @@ -16,15 +15,16 @@ public class PiperManager : MonoBehaviour
public int sampleRate = 22050;

private Model _runtimeModel;
private IWorker _worker;
private Worker _worker;

private void Awake()
{
var espeakPath = Path.Combine(Application.streamingAssetsPath, "espeak-ng-data");
PiperWrapper.InitPiper(espeakPath);

_runtimeModel = ModelLoader.Load(model);
_worker = WorkerFactory.CreateWorker(backend, _runtimeModel);
_worker = new Worker(_runtimeModel, backend);

}

public async Task<AudioClip> TextToSpeech(string text)
Expand All @@ -41,30 +41,28 @@ public async Task<AudioClip> TextToSpeech(string text)

var inputLengthsShape = new TensorShape(1);
var scalesShape = new TensorShape(3);
using var scalesTensor = new TensorFloat(scalesShape, new float[] { 0.667f, 1f, 0.8f });
using var scalesTensor = new Tensor<float>(scalesShape, new [] { 1f, 1f, 1f });

var audioBuffer = new List<float>();
for (int i = 0; i < phonemes.Sentences.Length; i++)
foreach (var sentence in phonemes.Sentences)
{
var sentence = phonemes.Sentences[i];

var inputPhonemes = sentence.PhonemesIds;
var inputShape = new TensorShape(1, inputPhonemes.Length);
using var inputTensor = new TensorInt(inputShape, inputPhonemes);
using var inputLengthsTensor = new TensorInt(inputLengthsShape, new int[] { inputPhonemes.Length });

var input = new Dictionary<string, Tensor>();
input.Add("input", inputTensor);
input.Add("input_lengths", inputLengthsTensor);
input.Add("scales", scalesTensor);
using var inputTensor = new Tensor<int>(inputShape, inputPhonemes);
using var inputLengthsTensor = new Tensor<int>(inputLengthsShape, new [] { inputPhonemes.Length });

_worker.Execute(input);
_worker.Schedule(inputTensor, inputLengthsTensor, scalesTensor);

using var outputTensor = _worker.PeekOutput() as TensorFloat;
await outputTensor.MakeReadableAsync();
using var outputTensor = _worker.PeekOutput() as Tensor<float>;
if (outputTensor != null)
{
await outputTensor.ReadbackAndCloneAsync();

var output = outputTensor.DownloadToArray();
Debug.Log(output.Length);

var output = outputTensor.ToReadOnlyArray();
audioBuffer.AddRange(output);
audioBuffer.AddRange(output);
}
}

Debug.Log($"Finished piper inference: {sw.ElapsedMilliseconds} ms");
Expand Down
16 changes: 14 additions & 2 deletions Assets/Piper/Scripts/PiperNative.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Runtime.InteropServices;
using UnityEngine;

namespace Piper.Native
{
Expand All @@ -20,8 +21,15 @@ public unsafe struct PiperProcessedTextNative

public static unsafe class PiperNative
{
private const string LibraryName = "piper_phonemize";

private const string LibraryName =

#if UNITY_STANDALONE_OSX
"libpiper_phonemize";

#elif UNITY_STANDALONE_WIN
"piper_phonemize";
#endif

[DllImport(LibraryName)]
public static extern int init_piper(string dataPath);

Expand All @@ -33,6 +41,10 @@ public static unsafe class PiperNative

[DllImport(LibraryName)]
public static extern void free_piper();
public static void PrintLibraryName()
{
Debug.Log(LibraryName);
}

}
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Piper/Scripts/PiperWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static bool InitPiper(string datapath)
Debug.LogError($"Provided espeak data path \"{datapath}\" doesn't exist!");
return false;
}

PiperNative.PrintLibraryName();
var code = PiperNative.init_piper(datapath);
if (code < 0)
{
Expand Down
Binary file added Assets/Piper/Scripts/en_US-danny-low.onnx
Binary file not shown.
10 changes: 10 additions & 0 deletions Assets/Piper/Scripts/en_US-danny-low.onnx.meta

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

Loading