Question

After using play() function the sound plays continuously. How do I stop it. The code below shows that I used the pause() function but that just gives me an error message, I've also tried using close() function.

> pause(saw)
Error in UseMethod("pause") : 
  no applicable method for 'pause' applied to an object of class "c('Wave', 'WaveGeneral')"
Was it helpful?

Solution

I guess you use these two different packages:

  • tuneR to import your wave file
  • audiofor its playback functions

Unfortunately these packages each have their own object classes: Wave class in tuneR and audioSample class in audio. If you want to use the playback functions of audio you first need an object of class audioSample. You can get this by importing your wave file with audio's own import function

mywav <- load.wave("myaudiosample.wav")

but since tuneR can also import mp3 files and has more import options it may be necessary to create your own audioSample object manually from a Wave object. A simple mono file for example could be converted the following way:

myWave <- readWave("myaudiosample.wav")
mywav <- audioSample(myWave@left, myWave@samp.rate, myWave@bit)

You can then use the playback functions from audio. Just make sure to call audio::play(), it might be masked by tuneR

a <- audio::play(mywav)
pause(a)
resume(a)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top