0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

No module named soundfile

0
Posted at

タイトル: [windows, uv環境でpythonのライブラリが見つからない(soundfile)]

はじめに

背景

windows11, uv環境でコード実行中にNo module named 'soundfile'が出てコードは動作できない。

対象読者

  • uvに興味がある方

環境

項目 バージョン/詳細
OS Windows 11
言語 Python 3.10
ライブラリ
その他 -
uv add asr-core pandas pysoundfile
uv remove pysoundfile
uv add asr-core pandas soundfile==0.13.1
※asr-coreは自前ライブラリ

問題

起きたエラー

No module named 'soundfile'

困っている点

  • コードは実行したらエラーとなり、先に進まない。

解決方法

手順 1: [librosaでワーニング]

説明文

UserWarning: PySoundFile failed. Trying audioread instead.
  y, sr = librosa.load(audio_path, sr=16000)

手順 2: [pysoundfileを取り入れたらsoundfileにはSoundFileRuntimeErrorがない]

説明文

uv add pysoundfile

module 'soundfile' has no attribute 'SoundFileRuntimeError'

手順 3: [pysoundfileを削除したらsoundfileが見つからない]

説明文

uv remove pysoundfile

No module named 'soundfile'

元に警告に戻れなくなり、ずっとこのエラー

関連のあるコード

コードを見る(クリックで展開)
import os
import glob
from pathlib import Path
#import whisper
from asr_core import transcribe
import pandas as pd
from datetime import timedelta
import numpy as np

# uv pip install torch==2.0.1 torchaudio==2.0.2

def format_time(seconds):
    """秒数を MM:SS 形式に変換"""
    td = timedelta(seconds=int(seconds))
    minutes = td.seconds // 60
    secs = td.seconds % 60
    return f"{minutes:02d}:{secs:02d}"

def detect_speech_start(audio_path, energy_threshold=0.02, window_size=0.1):
    """
    音声ファイルから実際の発話開始位置を自動検出

    Parameters:
    -----------
    audio_path : str
        音声/動画ファイルのパス
    energy_threshold : float
        音声と判定するエネルギー閾値
    window_size : float
        分析する窓のサイズ(秒)

    Returns:
    --------
    float
        実際の発話が始まる時刻(秒)
    """
    try:
        import librosa
    except ImportError:
        print("警告: librosaがインストールされていません")
        print("インストール: pip install librosa")
        print("発話開始位置の検出をスキップします")
        return 0.0

    print("  音声開始位置を検出中...")

    # 音声データを読み込み
    y, sr = librosa.load(audio_path, sr=16000)

結果

動作確認

実行結果:

処理中: /path/to/640x360.mp4
  音声開始位置を検出中...
  エラー: /path/to/640x360.mp4 の処理に失敗しました
  詳細: No module named 'soundfile'

期待通りの動作

  • ✅ librosa.loadが期待通り動作してほしい。

この記事が役に立ったら、いいね ❤️ やストック 📚 をお願いします!
質問やコメントもお気軽にどうぞ 💬

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?