Spaces:
Running
Running
File size: 1,345 Bytes
be5673e 23e60a0 be5673e 23e60a0 1a83c9e 8ff5286 1a83c9e be5673e 8ff5286 be5673e 9dfad5c be5673e 8ff5286 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
import gradio as gr
from transformers import WhisperProcessor, WhisperForConditionalGeneration
import torch
import librosa
# モデルとプロセッサの読み込み
model_name = "openai/whisper-large-v3"
processor = WhisperProcessor.from_pretrained(model_name)
model = WhisperForConditionalGeneration.from_pretrained(model_name)
# 音声ファイルを文字起こしする関数
def transcribe_audio(audio):
# librosaで音声を読み込む
audio_data, sampling_rate = librosa.load(audio, sr=16000)
# WhisperProcessorに渡すために、音声データを正しい形式に変換
audio_input = processor(audio_data, return_tensors="pt", sampling_rate=16000)
# input_features を取得
input_features = audio_input["input_features"]
# モデルによる文字起こし
with torch.no_grad():
predicted_ids = model.generate(input_features=input_features)
# 文字起こし結果のデコード
transcription = processor.decode(predicted_ids[0], skip_special_tokens=True)
return transcription
# Gradioのインターフェース作成
interface = gr.Interface(
fn=transcribe_audio,
inputs=gr.Audio(type="filepath"), # マイクやファイルから音声を入力
outputs="text",
live=True
)
# インターフェースの起動
interface.launch(share=True)
|