Skip to content

Commit

Permalink
Add option to return numpy from load_audio
Browse files Browse the repository at this point in the history
  • Loading branch information
keveman committed Oct 23, 2024
1 parent a0f03a4 commit 2e04ed3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion moonshine/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
from . import ASSETS_DIR


def load_audio(audio):
def load_audio(audio, return_numpy=False):
if isinstance(audio, (str, Path)):
import librosa

audio, _ = librosa.load(audio, sr=16_000)
if return_numpy:
return audio[None, ...]
audio = keras.ops.expand_dims(keras.ops.convert_to_tensor(audio), 0)
return audio

Expand All @@ -37,11 +39,13 @@ def transcribe(audio, model="moonshine/base"):
tokens = model.generate(audio)
return load_tokenizer().decode_batch(tokens)


def load_tokenizer():
tokenizer_file = ASSETS_DIR / "tokenizer.json"
tokenizer = tokenizers.Tokenizer.from_file(str(tokenizer_file))
return tokenizer


def benchmark(audio, model="moonshine/base"):
import time

Expand Down

0 comments on commit 2e04ed3

Please sign in to comment.