unity-sentis
ONNX
alexsuvorov commited on
Commit
148e5e2
·
verified ·
1 Parent(s): e97b228

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +4 -5
  2. RunJets.cs +8 -9
  3. info.json +13 -4
README.md CHANGED
@@ -3,16 +3,15 @@ license: cc-by-4.0
3
  library_name: unity-sentis
4
  ---
5
 
6
- # Jets Text-to-Speech Model validated for Unity Sentis (Version 1.4.0-pre.2*)
7
- *Version 1.3.0 Sentis files are not compatible with version 1.4.0 and above and will need to be recreated
8
 
9
  This is a text to speech model called [Jets](https://huggingface.co/imdanboy/jets). It takes in a text string which you convert to phonemes using a dictionary and then outputs a wav to play the voice.
10
 
11
  ## How to Use
12
- * Create a new scene in Unity 2023
13
- * Install `com.unity.sentis` version `1.4.0-pre.2` package
14
  * Put the c# script on the Main Camera
15
- * Put the `sentis` file and the `phoneme_dict.txt` file in the `Assets/StreamingAssets` folder
16
  * Add an AudioSource component on the Main Camera
17
  * Set the `inputText` string for what you want it to say
18
  * Press play
 
3
  library_name: unity-sentis
4
  ---
5
 
6
+ # Jets Text-to-Speech Model validated for Sentis 2.1.2 in Unity 6
 
7
 
8
  This is a text to speech model called [Jets](https://huggingface.co/imdanboy/jets). It takes in a text string which you convert to phonemes using a dictionary and then outputs a wav to play the voice.
9
 
10
  ## How to Use
11
+ * Create a new scene in Unity 6
12
+ * Install `com.unity.sentis` version `2.1.2` package
13
  * Put the c# script on the Main Camera
14
+ * Put the `jets-text-to-speech.sentis` file and the `phoneme_dict.txt` file in the `Assets/StreamingAssets` folder
15
  * Add an AudioSource component on the Main Camera
16
  * Set the `inputText` string for what you want it to say
17
  * Press play
RunJets.cs CHANGED
@@ -38,7 +38,7 @@ public class RunJets : MonoBehaviour
38
 
39
  Dictionary<string, string> dict = new ();
40
 
41
- IWorker engine;
42
 
43
  AudioClip clip;
44
 
@@ -51,8 +51,8 @@ public class RunJets : MonoBehaviour
51
 
52
  void LoadModel()
53
  {
54
- var model = ModelLoader.Load(Path.Join(Application.streamingAssetsPath ,"jets-text-to-speech.sentis"));
55
- engine = WorkerFactory.CreateWorker(BackendType.GPUCompute, model);
56
  }
57
 
58
  void TextToSpeech()
@@ -167,12 +167,11 @@ public class RunJets : MonoBehaviour
167
  {
168
  int[] tokens = GetTokens(ptext);
169
 
170
- using var input = new TensorInt(new TensorShape(tokens.Length), tokens);
171
- var result = engine.Execute(input);
172
 
173
- var output = result.PeekOutput("wav") as TensorFloat;
174
- output.CompleteOperationsAndDownload();
175
- var samples = output.ToReadOnlyArray();
176
 
177
  Debug.Log($"Audio size = {samples.Length / samplerate} seconds");
178
 
@@ -205,6 +204,6 @@ public class RunJets : MonoBehaviour
205
 
206
  private void OnDestroy()
207
  {
208
- engine?.Dispose();
209
  }
210
  }
 
38
 
39
  Dictionary<string, string> dict = new ();
40
 
41
+ Worker worker;
42
 
43
  AudioClip clip;
44
 
 
51
 
52
  void LoadModel()
53
  {
54
+ var model = ModelLoader.Load(Path.Join(Application.streamingAssetsPath, "jets-text-to-speech.sentis"));
55
+ worker = new Worker(model, BackendType.GPUCompute);
56
  }
57
 
58
  void TextToSpeech()
 
167
  {
168
  int[] tokens = GetTokens(ptext);
169
 
170
+ using var input = new Tensor<int>(new TensorShape(tokens.Length), tokens);
171
+ worker.Schedule(input);
172
 
173
+ using var samplesTensor = (worker.PeekOutput("wav") as Tensor<float>).ReadbackAndClone();
174
+ var samples = samplesTensor.AsReadOnlySpan();
 
175
 
176
  Debug.Log($"Audio size = {samples.Length / samplerate} seconds");
177
 
 
204
 
205
  private void OnDestroy()
206
  {
207
+ worker?.Dispose();
208
  }
209
  }
info.json CHANGED
@@ -1,6 +1,15 @@
1
  {
2
- "version" : [
3
- "1.4.0"
4
- ]
5
-
 
 
 
 
 
 
 
 
 
6
  }
 
1
  {
2
+ "code": [
3
+ "RunJets.cs"
4
+ ],
5
+ "models": [
6
+ "jets-text-to-speech.onnx",
7
+ "jets-text-to-speech.sentis"
8
+ ],
9
+ "data": [
10
+ "phoneme_dict.txt"
11
+ ],
12
+ "version": [
13
+ "2.1.2"
14
+ ]
15
  }