Skip to content

Commit 70e1c3f

Browse files
com.rest.elevenlabs 1.3.1 (#13)
- Add ability to serialize voice and voice settings in inspector
1 parent 3e7e49a commit 70e1c3f

File tree

7 files changed

+74
-8
lines changed

7 files changed

+74
-8
lines changed

Editor/VoicePropertyDrawer.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Licensed under the MIT License. See LICENSE in the project root for license information.
2+
3+
using ElevenLabs.Voices;
4+
using UnityEditor;
5+
using UnityEngine;
6+
7+
namespace ElevenLabs.Editor
8+
{
9+
[CustomPropertyDrawer(typeof(Voice))]
10+
public class VoicePropertyDrawer : PropertyDrawer
11+
{
12+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
13+
{
14+
var voiceName = property.FindPropertyRelative("name");
15+
var id = property.FindPropertyRelative("id");
16+
EditorGUI.LabelField(position, new GUIContent("Voice"), new GUIContent(voiceName.stringValue, id.stringValue));
17+
}
18+
}
19+
}

Editor/VoicePropertyDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Voices/Voice.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// Licensed under the MIT License. See LICENSE in the project root for license information.
22

33
using Newtonsoft.Json;
4+
using System;
45
using System.Collections.Generic;
6+
using UnityEngine;
57

68
namespace ElevenLabs.Voices
79
{
10+
[Serializable]
811
public sealed class Voice
912
{
1013
public Voice(string id)
@@ -33,11 +36,25 @@ public Voice(
3336
Settings = settings;
3437
}
3538

36-
[JsonProperty("voice_id")]
37-
public string Id { get; }
39+
[SerializeField]
40+
private string name;
3841

3942
[JsonProperty("name")]
40-
public string Name { get; }
43+
public string Name
44+
{
45+
get => name;
46+
private set => name = value;
47+
}
48+
49+
[SerializeField]
50+
private string id;
51+
52+
[JsonProperty("voice_id")]
53+
public string Id
54+
{
55+
get => id;
56+
private set => id = value;
57+
}
4158

4259
[JsonProperty("samples")]
4360
public IReadOnlyList<Sample> Samples { get; }

Runtime/Voices/VoiceSettings.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// Licensed under the MIT License. See LICENSE in the project root for license information.
22

3+
using System;
34
using Newtonsoft.Json;
5+
using UnityEngine;
46

57
namespace ElevenLabs.Voices
68
{
9+
[Serializable]
710
public sealed class VoiceSettings
811
{
912
[JsonConstructor]
@@ -15,10 +18,26 @@ public VoiceSettings(
1518
SimilarityBoost = similarityBoost;
1619
}
1720

21+
[Range(0f, 1f)]
22+
[SerializeField]
23+
private float stability = 0.75f;
24+
1825
[JsonProperty("stability")]
19-
public float Stability { get; }
26+
public float Stability
27+
{
28+
get => stability;
29+
private set => stability = value;
30+
}
31+
32+
[Range(0f, 1f)]
33+
[SerializeField]
34+
private float similarityBoost = 0.75f;
2035

2136
[JsonProperty("similarity_boost")]
22-
public float SimilarityBoost { get; }
37+
public float SimilarityBoost
38+
{
39+
get => similarityBoost;
40+
private set => similarityBoost = value;
41+
}
2342
}
2443
}

Tests/Test_Fixture_03_TextToSpeechEndpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public async Task Test_01_TextToSpeech()
1515
{
1616
var api = new ElevenLabsClient(ElevenLabsAuthentication.LoadFromEnv());
1717
Assert.NotNull(api.TextToSpeechEndpoint);
18-
var voice = (await api.VoicesEndpoint.GetAllVoicesAsync()).FirstOrDefault();
18+
var voice = Voices.Voice.Adam;
1919
Assert.NotNull(voice);
2020
var defaultVoiceSettings = await api.VoicesEndpoint.GetDefaultVoiceSettingsAsync();
2121
var (clipPath, audioClip) = await api.TextToSpeechEndpoint.TextToSpeechAsync("The quick brown fox jumps over the lazy dog.", voice, defaultVoiceSettings, deleteCachedFile: true);

Tests/Test_Fixture_06_Models.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "ElevenLabs",
44
"description": "A non-official Eleven Labs voice synthesis RESTful client.",
55
"keywords": [],
6-
"version": "1.3.0",
6+
"version": "1.3.1",
77
"unity": "2021.3",
88
"documentationUrl": "https://github.com/RageAgainstThePixel/com.rest.elevenlabs#documentation",
99
"changelogUrl": "https://github.com/RageAgainstThePixel/com.rest.elevenlabs/releases",

0 commit comments

Comments
 (0)