Skip to content

Commit

Permalink
setter for modelPath #36 (#37)
Browse files Browse the repository at this point in the history
also, added new field to determine whether the StreamingAssets folder should be prepended
  • Loading branch information
achimmihca committed Jun 22, 2023
1 parent 2ff649c commit bd58b68
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions Packages/com.whisper.unity/Runtime/WhisperManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,38 @@ namespace Whisper
public class WhisperManager : MonoBehaviour
{
[SerializeField]
[Tooltip("Path to model weights file relative to StreamingAssets")]
[Tooltip("Path to model weights file")]
private string modelPath = "Whisper/ggml-base.bin";
public string ModelPath
{
get => modelPath;
set
{
if (IsLoaded || IsLoading)
{
throw new InvalidOperationException("Cannot change model path after loading the model");
}

modelPath = value;
}
}

[SerializeField]
[Tooltip("Determines whether the StreamingAssets folder should be prepended to the model path")]
private bool isModelPathInStreamingAssets = true;
public bool IsModelPathInStreamingAssets
{
get => isModelPathInStreamingAssets;
set
{
if (IsLoaded || IsLoading)
{
throw new InvalidOperationException("Cannot change model path after loading the model");
}

isModelPathInStreamingAssets = value;
}
}

[SerializeField]
[Tooltip("Should model weights be loaded on awake?")]
Expand Down Expand Up @@ -97,7 +127,9 @@ public async Task InitModel()
IsLoading = true;
try
{
var path = Path.Combine(Application.streamingAssetsPath, modelPath);
var path = IsModelPathInStreamingAssets
? Path.Combine(Application.streamingAssetsPath, modelPath)
: modelPath;
_whisper = await WhisperWrapper.InitFromFileAsync(path);
_params = WhisperParams.GetDefaultParams(strategy);
_whisper.OnNewSegment += OnNewSegmentHandler;
Expand Down Expand Up @@ -196,5 +228,4 @@ private void OnProgressHandler(int progress)
});
}
}
}

}

0 comments on commit bd58b68

Please sign in to comment.