前提・実現したいこと
WAVファイルを学習してMP3ファイルの音質を復元するニューラルネットワークを実装しているときに、以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
Traceback (most recent call last): File "C:\Users\sukep\AppData\Local\Programs\Python\Python39\Projects\Repair Audio\main.py", line 27, in <module> mp3 = Audio("Alan Walker - Faded.mp3") File "C:\Users\sukep\AppData\Local\Programs\Python\Python39\Projects\Repair Audio\main.py", line 14, in __init__ self.sound = AudioSegment.from_file(filename) File "C:\Users\sukep\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\audio_segment.py", line 728, in from_file info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit) File "C:\Users\sukep\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\utils.py", line 279, in mediainfo_json info = json.loads(output) File "C:\Users\sukep\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 346, in loads return _default_decoder.decode(s) File "C:\Users\sukep\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Users\sukep\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
該当のソースコード
Python
1from keras.models import Sequential 2from keras.layers import Dense, Activation 3from pydub import AudioSegment 4import numpy as np 5import matplotlib.pyplot as plt 6import random 7 8 9BUFFER_SIZE = 256 10 11 12class Audio: 13 def __init__(self, filename): 14 self.sound = AudioSegment.from_file(filename) 15 self.samples = np.array(self.sound.get_array_of_samples()) 16 17 if self.sound.channels == 1: 18 self.left = self.samples 19 self.right = self.samples 20 else: 21 self.left = self.samples[::2] 22 self.right = self.samples[1::2] 23 24 25if __name__ == "__main__": 26 wav = Audio("Alan Walker - Faded.wav") 27 mp3 = Audio("Alan Walker - Faded.mp3") 28 29 offset = random.randrange(wav.left.size-BUFFER_SIZE) 30 31 if random.randrange() == 0: 32 x_train = mp3.left[offset:BUFFER_SIZE] 33 y_train = wav.left[offset:BUFFER_SIZE] 34 else: 35 x_train = mp3.right[offset:BUFFER_SIZE] 36 y_train = wav.right[offset:BUFFER_SIZE] 37 38 model = Sequrntial() 39 model.add(Dense(BUFFER_SIZE, input_dim=BUFFER_SIZE)) 40 model.add(Activation("linear")) 41 model.add(Dense(BUFFER_SIZE)) 42 model.add(Activation("linear")) 43 44 model.compile(optimizer="adam", loss="mse", metrics=["accuracy"]) 45 model.fit(x=x_train, y=y_train, epochs=20) 46
補足情報(FW/ツールのバージョンなど)
IDLE Shell 3.9.7
ffmpeg-N-103611-gdb2514a5dc-win64-gpl-shared
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。