generated from RageAgainstThePixel/upm-template
-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- refactored AudioEndpoint speech requests - added AudioEndpoint.GetSpeechAsync - deprecated AudioEndpoint.CreateSpeechAsync - deprecated AudioEndpoint.CreateSpeechStreamAsync - added SpeechClip response - added Realtime.ResponseAudioResponse.AudioSamples - updated all sample scenes with new OnAudioFilterRead examples for better playback - updated unit tests
- Loading branch information
1 parent
2e54704
commit 79a919a
Showing
15 changed files
with
755 additions
and
669 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
OpenAI/Packages/com.openai.unity/Runtime/Audio/SpeechClip.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using System; | ||
using UnityEngine; | ||
using UnityEngine.Scripting; | ||
using Utilities.Audio; | ||
|
||
namespace OpenAI.Audio | ||
{ | ||
[Preserve] | ||
public sealed class SpeechClip | ||
{ | ||
[Preserve] | ||
internal SpeechClip(string name, string cachePath, ReadOnlyMemory<byte> audioData, int sampleRate = 24000) | ||
{ | ||
Name = name; | ||
CachePath = cachePath; | ||
AudioData = audioData; | ||
SampleRate = sampleRate; | ||
} | ||
|
||
[Preserve] | ||
public string Name { get; } | ||
|
||
[Preserve] | ||
public string CachePath { get; } | ||
|
||
[Preserve] | ||
public ReadOnlyMemory<byte> AudioData { get; } | ||
|
||
[Preserve] | ||
public float[] AudioSamples | ||
=> PCMEncoder.Resample(PCMEncoder.Decode(AudioData.ToArray()), SampleRate, 44100); | ||
|
||
[Preserve] | ||
public int SampleRate { get; } | ||
|
||
[Preserve] | ||
public AudioClip AudioClip | ||
{ | ||
get | ||
{ | ||
var samples = AudioSamples; | ||
var clip = AudioClip.Create(Name, samples.Length, 1, 44100, false); | ||
clip.SetData(samples, 0); | ||
return clip; | ||
} | ||
} | ||
|
||
[Preserve] | ||
public static implicit operator AudioClip(SpeechClip clip) => clip?.AudioClip; | ||
|
||
[Preserve] | ||
public static implicit operator string(SpeechClip clip) => clip?.CachePath; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
OpenAI/Packages/com.openai.unity/Runtime/Audio/SpeechClip.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.