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

Register audio #11

Open
giorgionanfa opened this issue Jun 9, 2019 · 0 comments
Open

Register audio #11

giorgionanfa opened this issue Jun 9, 2019 · 0 comments

Comments

@giorgionanfa
Copy link

giorgionanfa commented Jun 9, 2019

Hi, your work is very interesting! I would like to register the audio in a file.wav after stopping the real time stream. Hence, i add a frames list in SWHear.py and i update it in this way:

def stream_readchunk(self):
"""reads some audio and re-launches itself"""

    try:
        self.data = np.fromstring(self.stream.read(self.chunk, exception_on_overflow=False),dtype=np.int16)
        self.fftx, self.fft = getFFT(self.data,self.rate)
        for i in range(0, int(self.rate / self.chunk*5)):
            frames.append(self.stream.read(self.chunk, exception_on_overflow=False))

Then, i pass frames to go.py and save the audio in this way:
waveFile = wave.open("test_file.wav", 'wb')
waveFile.setnchannels(1)
waveFile.setsampwidth(pyaudio.PyAudio().get_sample_size(pyaudio.paInt16))
waveFile.setframerate(44100)
waveFile.writeframes(b''.join(SWHear.frames))
waveFile.close()

Now, my problem is that the for loop that i added in SWHear.py creates a great delay in the graphic interface. If i remove it, the saved test_file.wav is sampled uncorrectly. Do you have some idea to solve this problem? Or a simpler way to implement this thing?

Moreover, sometimes i observe the following error:

ALSA lib pcm_dsnoop.c:638:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dsnoop.c:638:(snd_pcm_dsnoop_open) unable to open slave
Expression 'ret' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1736

Using the microphone of my pc, it seems that only sometimes the program does not recognize it. Why?
Thanks in advance,
Giorgio

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

1 participant