実現したいこと
エラーの内容と解決法を教えてほしい
発生している問題・分からないこと
エラーの内容がわからない
エラーメッセージ
error
1PS C:\Users\2121093> & C:/Users/2121093/AppData/Local/Microsoft/WindowsApps/python3.10.exe c:/Users/2121093/AppData/Local/Programs/Python/Python312/main.py 2Traceback (most recent call last): 3 File "c:\Users\2121093\AppData\Local\Programs\Python\Python312\main.py", line 4, in <module> 4 from feat import Detector 5 File "C:\Users\2121093\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\feat\__init__.py", line 11, in <module> 6 from .data import Fex 7 File "C:\Users\2121093\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\feat\data.py", line 30, in <module> 8 from feat.utils.stats import wavelet, calc_hist_auc, cluster_identities 9 File "C:\Users\2121093\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\feat\utils\stats.py", line 7, in <module> 10 from scipy.integrate import simps 11ImportError: cannot import name 'simps' from 'scipy.integrate' (C:\Users\2121093\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\scipy\integrate\__init__.py)
該当のソースコード
python
1import os 2import subprocess 3import speech_recognition as sr 4from feat import Detector 5from empath import Empath 6from transformers import pipeline 7from pyannote.audio import Pipeline 8import cv2 9 10# ==== 1. 動画から音声を抽出 ==== 11def extract_audio(video_path, audio_path="extracted_audio.wav"): 12 print("動画から音声を抽出中...") 13 subprocess.run(["ffmpeg", "-i", video_path, "-q:a", "0", "-map", "a", audio_path, "-y"]) 14 print(f"音声が {audio_path} に保存されました。") 15 return audio_path 16 17# ==== 2. 音声分離 (話者分離) ==== 18def diarize_audio(audio_path, model_path="pyannote/speaker-diarization"): 19 print("話者分離中...") 20 pipeline = Pipeline.from_pretrained(model_path) 21 diarization = pipeline(audio_path) 22 segments = [] 23 24 for turn, _, speaker in diarization.itertracks(yield_label=True): 25 segments.append({ 26 "start": turn.start, 27 "end": turn.end, 28 "speaker": speaker 29 }) 30 return segments 31 32# ==== 3. 音声認識 (テキスト化) ==== 33def transcribe_audio(audio_path, start, end): 34 recognizer = sr.Recognizer() 35 with sr.AudioFile(audio_path) as source: 36 audio = recognizer.record(source, offset=start, duration=end-start) 37 try: 38 return recognizer.recognize_google(audio, language="ja-JP") 39 except Exception: 40 return "" 41 42# ==== 4. 音声感情解析 (Empath) ==== 43def analyze_audio_emotion(word): 44 lexicon = Empath() 45 return lexicon.analyze(word, normalize=True) 46 47# ==== 5. 表情感情解析 (py-feat) ==== 48def analyze_facial_emotion(video_path, start_time, end_time, detector): 49 cap = cv2.VideoCapture(video_path) 50 cap.set(cv2.CAP_PROP_POS_MSEC, start_time * 1000) 51 frame_count = 0 52 emotions = [] 53 54 while cap.get(cv2.CAP_PROP_POS_MSEC) < end_time * 1000: 55 ret, frame = cap.read() 56 if not ret: 57 break 58 if frame_count % 30 == 0: # 30フレームごとに解析 59 try: 60 result = detector.detect_image(frame) 61 emotions.append(result["emotions"].mean().idxmax()) 62 except Exception: 63 pass 64 frame_count += 1 65 66 cap.release() 67 return emotions 68 69# ==== 6. テキスト感情解析 (BERT) ==== 70def analyze_text_emotion(text): 71 emotion_pipeline = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment") 72 return emotion_pipeline(text) 73 74# ==== 7. 解析結果をTXTに保存 ==== 75def save_results_to_txt(results, output_file="results.txt"): 76 with open(output_file, "w", encoding="utf-8") as file: 77 for result in results: 78 file.write(f"Speaker: {result['speaker']}\n") 79 file.write(f"Recognized Text: {result['text']}\n") 80 file.write(f"Audio Emotion: {result['audio_emotion']}\n") 81 file.write(f"Facial Emotions: {', '.join(result['facial_emotions'])}\n") 82 file.write(f"Text Emotion: {result['text_emotion']}\n") 83 file.write("\n") 84 print(f"解析結果が {output_file} に保存されました。") 85 86# ==== 8. メイン処理 ==== 87def main(video_path): 88 # 音声抽出 89 audio_path = extract_audio(video_path) 90 91 # 話者分離 92 segments = diarize_audio(audio_path) 93 detector = Detector() 94 results = [] 95 96 # 各セグメントごとに解析 97 for segment in segments: 98 start, end = segment["start"], segment["end"] 99 speaker = segment["speaker"] 100 print(f"解析中: 話者 {speaker}, 時間 {start} - {end}") 101 102 # 音声認識 103 word = transcribe_audio(audio_path, start, end) 104 105 # 音声感情解析 106 audio_emotion = analyze_audio_emotion(word) 107 108 # 表情感情解析 109 facial_emotions = analyze_facial_emotion(video_path, start, end, detector) 110 111 # テキスト感情解析 112 text_emotion = analyze_text_emotion(word) if word else "No Text" 113 114 # 結果保存 115 results.append({ 116 "speaker": speaker, 117 "word": word, 118 "audio_emotion": audio_emotion, 119 "facial_emotions": facial_emotions, 120 "text_emotion": text_emotion 121 }) 122 123 # 結果をテキストファイルに保存 124 save_results_to_txt(results) 125 126if __name__ == "__main__": 127 video_path = "input_video.mp4" # 入力動画ファイルのパス 128 main(video_path)
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
別のエラーを解決したが別のエラーが出てきた
SciPy のバージョンを1.14に変更した
補足
特になし
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2024/12/22 08:43
2024/12/22 08:56
2024/12/22 09:22
2024/12/22 09:32
2024/12/22 09:33
2024/12/22 09:44
2024/12/22 10:03
2024/12/22 10:19
2024/12/22 11:29
2024/12/22 11:36
2024/12/22 12:44