tyiannak / pyAudioAnalysis

Python Audio Analysis Library: Feature Extraction, Classification, Segmentation and Applications
Apache License 2.0
5.75k stars 1.18k forks source link

open wav file for analyse #399

Open PeterBan11 opened 3 months ago

PeterBan11 commented 3 months ago

Hello, everyone!

I want to open wav file for analyse with this code(but it doesn't work):

import os import wave import pyaudio import numpy as np import tkinter as tk from tkinter import ttk from tkinter import filedialog from pydub import AudioSegment class Full: def init(self, parent): self.pa = pyaudio.PyAudio() self.chunk_size = 1024 self.sample_rate = 44100 self.window = parent def start_analyzing_WavFile(self): try: file_Extension = self.path.split(".")[1].lower() if file_Extension == "wav": wavFile = wave.open(self.wavFileName, 'r') elif file_Extension == "mp3": cwd = os.getcwd() sound = AudioSegment.from_mp3(self.wavFileName) self.wavFileName = f"{cwd}/tmp.wav" sound.export(self.wavFileName, format="wav") wavFile = wave.open(self.wavFileName, 'r') else: print(f"Unknown Type of File: {file_Extension}") except IOError as e: print(u'cant open wavFile file') else: with wavFile: self.stream = self.pa.open(format=self.pa.get_format_from_width(wavFile.getsampwidth()), channels=wavFile.getnchannels(), rate=wavFile.getframerate(), input=True, frames_per_buffer=self.chunk_size, stream_callback=self.read_callback)
PeterBan11 commented 3 months ago

I will appreciate any help...

Caparrini commented 3 months ago

Why the code does not work?