R voice-recording

810 views Asked by At

Voice-recording problem in R

I've been trying to write a code which would record sound from microphone in R. I found function record {audio}. and used example shown in function description ( here : ). However it works only for first one time, I can see the result, plot it, but when I try to record second time program just freezes. Whole console needs to be restarted. I tried on a few computers (with diffrent OS) but with the same result. Did anyone have the same problem? Or is there any other way to record voice in R? It is going to be a part of voice-recognition system.
Edit. There is also one thing that I skipped. The code I'm using is shown below. This is exactly the same as in example in documentation. Even though, the play fucntion doesn't work.

x <- rep(NA_real_, 16000)
# start recording into x
record(x, 8000, 1)
# monitor the recording progress
par(ask=FALSE) # for continuous plotting
while (is.na(x[length(x)])) plot(x, type='l', ylim=c(-1, 1))
# play the recorded audio
play(x)
1

There are 1 answers

0
Etienne Bruines On

Both play and record return asynchronously. I can imagine the second record-call is being called before completion (causing the audio device to be in-use), and perhaps even the where-channel being in use because of that.

Possible fixes include:

  • Sleeping some time between the two recordings
  • Reinitializing the where-part in record
  • ...