File size: 1,937 Bytes
9222a32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
# app.py
import streamlit as st
from faster_whisper import WhisperModel
import tempfile
from pydub import AudioSegment
from pydub.utils import which

# ffmpegの場所をpydubに教える
AudioSegment.converter = which("ffmpeg")

# 画面のタイトルなど
st.set_page_config(page_title="文字起こしアプリ", layout="centered")
st.title("🎤 日本語文字起こし(無料)")

# モデルの選択(初心者は small がおすすめ)
model_size = st.selectbox("使うモデルの大きさ", ["tiny", "base", "small", "medium", "large-v2"])

# ファイルアップロード欄
uploaded_file = st.file_uploader("音声ファイルを選んでね(mp3, wavなど)", type=["mp3", "wav", "m4a"])

if uploaded_file:
    st.audio(uploaded_file)

    # 一時ファイルとして保存
    with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp:
        tmp.write(uploaded_file.read())
        audio_path = tmp.name

    if st.button("▶️ 文字起こしスタート!"):
        progress = st.progress(0)
        status = st.empty()

        # ステップ1:文字起こしモデルを読み込む
        status.info("Whisperモデルを準備中...")
        model = WhisperModel(model_size, compute_type="int8")
        progress.progress(30)

        # ステップ2:文字起こし実行
        status.info("文字起こし中...")
        segments, info = model.transcribe(audio_path, language="ja", vad_filter=True)
        progress.progress(80)

        # ステップ3:結果をまとめて表示
        text = "\n".join([segment.text for segment in segments])
        st.success("完了!こちらが結果です👇")
        st.text_area("文字起こし結果", value=text, height=300)
        progress.progress(100)

        # ステップ4:ダウンロードボタン
        st.download_button("💾 TXTで保存", data=text, file_name="transcription.txt", mime="text/plain")