import numpy as np
import soundfile
from moviepy.editor import VideoFileClip
import pywt
def extract_audio(input_video_path, output_audio_path):
video_clip = VideoFileClip(input_video_path)
audio_clip = video_clip.audio
audio_data = np.array(audio_clip.to_soundarray(fps=44100), dtype=np.int16)
if len(audio_data.shape) > 1 and audio_data.shape[1] > 1:
audio_data = np.mean(audio_data, axis=1, dtype=np.int16)
soundfile.write(output_audio_path, audio_data, audio_clip.fps)
def denoise_audio(input_audio_path, output_audio_path, threshold=0.2):
audio_data, rate = soundfile.read(input_audio_path)
# Wavelet denoising
threshold_value = threshold * np.max(np.abs(audio_data))
denoised_data = pywt.threshold(audio_data, value=threshold_value, mode='soft')
soundfile.write(output_audio_path, denoised_data, rate)
# Example usage
input_video_path = "Orson Welles Audio.mp4"
output_audio_path_extracted = "Extracted_Orson_Welles_Audio.wav"
output_audio_path_denoised = "Denoised_Orson_Welles_Audio.wav"
# Extract audio from video
extract_audio(input_video_path, output_audio_path_extracted)
# Denoise the extracted audio
denoise_audio(output_audio_path_extracted, output_audio_path_denoised, threshold=0.2)
It should extract the audio, denoise it, and put the new audio in a file but it gets stuck on the same error.
TypeError: arrays to stack must be passed as a "sequence" type such as list or tuple.
I can't see where the mistake is can anyone point it out? I tried changing the file types but it didn't help.