Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open wav file for analyse #399

Open
PeterBan11 opened this issue Apr 4, 2024 · 2 comments
Open

open wav file for analyse #399

PeterBan11 opened this issue Apr 4, 2024 · 2 comments

Comments

@PeterBan11
Copy link

PeterBan11 commented Apr 4, 2024

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
Copy link
Author

I will appreciate any help...

@Caparrini
Copy link

Why the code does not work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants