-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df72baa
commit 7df2da2
Showing
6 changed files
with
72 additions
and
2 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
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,30 @@ | ||
from transformers import AutomaticSpeechRecognitionPipeline, pipeline | ||
|
||
from todd.utils import get_audio | ||
|
||
audio, _ = get_audio( | ||
'https://github.com/SWivid/F5-TTS/raw/refs/heads/main/' | ||
'src/f5_tts/infer/examples/basic/basic_ref_zh.wav', | ||
) | ||
|
||
pipe: AutomaticSpeechRecognitionPipeline = pipeline( | ||
'automatic-speech-recognition', | ||
model='pretrained/whisper/whisper-large-v3-turbo', | ||
torch_dtype='auto', | ||
device_map='auto', | ||
) | ||
|
||
result = pipe(audio) | ||
print(result) | ||
|
||
result = pipe(audio, generate_kwargs=dict(language='zh')) | ||
print(result) | ||
|
||
result = pipe(audio, generate_kwargs=dict(task='translate', language='en')) | ||
print(result) | ||
|
||
result = pipe(audio, return_timestamps=True) | ||
print(result) | ||
|
||
result = pipe(audio, return_timestamps='word') | ||
print(result) |
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,17 @@ | ||
Whisper | ||
======= | ||
|
||
.. code-block:: bash | ||
root=pretrained/whisper | ||
mkdir -p ${root} && cd ${root} | ||
git clone git@hf.co:openai/whisper-large-v3-turbo | ||
.. code:: | ||
pretrained/whisper/ | ||
└── whisper-large-v3-turbo | ||
.. literalinclude:: whisper.py | ||
:language: python | ||
:linenos: |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,29 @@ | ||
__all__ = [ | ||
'get_bytes', | ||
'get_image', | ||
'get_audio', | ||
] | ||
|
||
from io import BytesIO | ||
|
||
import numpy as np | ||
import numpy.typing as npt | ||
import requests | ||
import soundfile as sf | ||
from PIL import Image | ||
|
||
|
||
def get_image(url: str) -> npt.NDArray[np.uint8]: | ||
def get_bytes(url: str) -> BytesIO: | ||
response = requests.get(url, timeout=5) | ||
response.raise_for_status() | ||
with Image.open(BytesIO(response.content)) as image: | ||
return BytesIO(response.content) | ||
|
||
|
||
def get_image(url: str) -> npt.NDArray[np.uint8]: | ||
with Image.open(get_bytes(url)) as image: | ||
image = image.convert('RGB') | ||
return np.array(image) | ||
|
||
|
||
def get_audio(url: str) -> tuple[npt.NDArray[np.float64], int]: | ||
return sf.read(get_bytes(url)) |