Skip to content

Commit 80066ad

Browse files
committed
Fix logging error by update Burst version
1 parent b4361eb commit 80066ad

13 files changed

+446
-33
lines changed

Assets/Mochineko/WhisperAPI.Samples/TranscriptionSample.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#nullable enable
22
using System;
3+
using System.IO;
34
using System.Net.Http;
45
using System.Threading;
56
using Assets.Mochineko.WhisperAPI;
@@ -19,8 +20,7 @@ public sealed class TranscriptionSample : MonoBehaviour
1920
/// <summary>
2021
/// File path of speech audio.
2122
/// </summary>
22-
[SerializeField]
23-
private string filePath = string.Empty;
23+
[SerializeField] private string filePath = string.Empty;
2424

2525
private static readonly HttpClient httpClient = new();
2626

@@ -44,7 +44,16 @@ public void Transcribe()
4444
private async UniTask TranscribeAsync(CancellationToken cancellationToken)
4545
{
4646
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY");
47-
47+
if (string.IsNullOrEmpty(apiKey))
48+
{
49+
throw new NullReferenceException(nameof(apiKey));
50+
}
51+
52+
var absoluteFilePath = Path.Combine(
53+
Application.dataPath,
54+
"..",
55+
filePath);
56+
4857
requestParameters.File = filePath;
4958

5059
Log.Debug("[Whisper_API.Samples] Begin to transcribe.");
@@ -56,7 +65,7 @@ private async UniTask TranscribeAsync(CancellationToken cancellationToken)
5665
.TranscribeFileAsync(
5766
apiKey,
5867
httpClient,
59-
filePath,
68+
absoluteFilePath,
6069
requestParameters,
6170
innerCancellationToken,
6271
debug: true),

Assets/Mochineko/WhisperAPI.Samples/TranslationSample.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ public void Translate()
3939
private async UniTask TranslateAsync(CancellationToken cancellationToken)
4040
{
4141
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY");
42+
if (string.IsNullOrEmpty(apiKey))
43+
{
44+
throw new NullReferenceException(nameof(apiKey));
45+
}
4246

4347
requestParameters.File = filePath;
4448

45-
await UniTask.SwitchToThreadPool();
46-
4749
Debug.Log($"[Whisper_API.Samples] Begin to translate.");
4850

4951
// Translate speech into English text by Whisper transcription API.
@@ -59,8 +61,6 @@ private async UniTask TranslateAsync(CancellationToken cancellationToken)
5961
debug: true),
6062
cancellationToken);
6163

62-
await UniTask.SwitchToMainThread(cancellationToken);
63-
6464
switch (result)
6565
{
6666
// Success

0 commit comments

Comments
 (0)