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 #397

Closed PeterBan11 closed 3 months ago

PeterBan11 commented 3 months ago

Hello, everyone!

I want to open wav file for analyse with this code:

wavFile = wave.open(self.wavFileName, 'r') 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)

But i get this problem:

RuntimeWarning: invalid value encountered in cast r = pfi.execute(a, is_real, is_forward, fct)

Caparrini commented 3 months ago

Hi! I'd like to help you. To better understand and replicate your situation, could you please provide the following information?

  1. Which version of Python are you using?
  2. Your code references 'self', indicating it's part of a class. Could you provide more context or the object's class definition.
  3. It would be helpful to know which libraries you have installed. Running pip freeze in a terminal will list your installed libraries.

Best regards,

PeterBan11 commented 3 months ago

Python 3.11

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)