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

Add functionality to read wav file #20

Open
kootenpv opened this issue May 16, 2022 · 2 comments
Open

Add functionality to read wav file #20

kootenpv opened this issue May 16, 2022 · 2 comments

Comments

@kootenpv
Copy link

Unfortunately doesn't work with:

wf = wave.open("my.wav", "rb")

self.stream = p.open(
    format=p.get_format_from_width(wf.getsampwidth()),
    channels=wf.getnchannels(),
    rate=wf.getframerate(),
    output=True,
    stream_callback=self.callback,
)
@EdoardoMor
Copy link

I think it should work like this, i will try it next weekend: (pseudo code):

import pyaudio import wave import numpy as np from Realtime_PyAudio_FFT import Visualization

Read audio file

audio_file = "path_to_audiofile.mp3" wf = wave.open(audio_file, 'rb')

Initialization of the PyAudio library and the Visualization object

p = pyaudio.pyAudio() visualization = visualization()

Set parameters for audio playback

stream = p.open( format=p.get_format_from_width(wf.getsampwidth()), channels=wf.getnchannels(), rate=wf.getframerate(), output=True, stream_callback=visualization.callback, # Callback callback function callback for animation )

Audio creation

data = wf.readframes(1024) whiledata: stream.write(data) data = wf.readframes(1024)

End the thread and clean up the resources

stream.stop_stream() stream.close() p.terminate()

Did you manage to write the full code and does it work?

@nordost8
Copy link

I think it should work like this, i will try it next weekend: (pseudo code):
import pyaudio import wave import numpy as np from Realtime_PyAudio_FFT import Visualization

Read audio file

audio_file = "path_to_audiofile.mp3" wf = wave.open(audio_file, 'rb')

Initialization of the PyAudio library and the Visualization object

p = pyaudio.pyAudio() visualization = visualization()

Set parameters for audio playback

stream = p.open( format=p.get_format_from_width(wf.getsampwidth()), channels=wf.getnchannels(), rate=wf.getframerate(), output=True, stream_callback=visualization.callback, # Callback callback function callback for animation )

Audio creation

data = wf.readframes(1024) whiledata: stream.write(data) data = wf.readframes(1024)

End the thread and clean up the resources

stream.stop_stream() stream.close() p.terminate()

Did you manage to write the full code and does it work?

do you want to specify the path to the file and see everything just like with the microphone? I could make a fork and add such functionality there, if someone really needs it :)

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

3 participants