Skip to content

Commit

Permalink
Add mel_spectrogram_device parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
take0x committed Sep 22, 2024
1 parent 834662c commit c1031a5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion whisper/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def transcribe(
append_punctuations: str = "\"'.。,,!!??::”)]}、",
clip_timestamps: Union[str, List[float]] = "0",
hallucination_silence_threshold: Optional[float] = None,
mel_spectrogram_device: Optional[Union[str, torch.device]] = None,
**decode_options,
):
"""
Expand Down Expand Up @@ -113,6 +114,9 @@ def transcribe(
When word_timestamps is True, skip silent periods longer than this threshold (in seconds)
when a possible hallucination is detected
mel_spectrogram_device: Optional[Union[str, torch.device]]
If given, the audio tensor is moved to this device before STFT
Returns
-------
A dictionary containing the resulting text ("text") and segment-level details ("segments"), and
Expand All @@ -131,7 +135,7 @@ def transcribe(

# Pad 30-seconds of silence to the input audio, for slicing
mel = log_mel_spectrogram(
audio, model.dims.n_mels, padding=N_SAMPLES, device=model.device
audio, model.dims.n_mels, padding=N_SAMPLES, device=mel_spectrogram_device
)
content_frames = mel.shape[-1] - N_FRAMES
content_duration = float(content_frames * HOP_LENGTH / SAMPLE_RATE)
Expand Down

0 comments on commit c1031a5

Please sign in to comment.