Audio record in R

后端 未结 2 922
南旧
南旧 2021-01-27 02:06

I am playing with some audio and sound packages in R for Windows (mine is Win7 x64). There is a problem when I tried to record from microphone using record() {audio} :

2条回答
  •  萌比男神i
    2021-01-27 02:40

    You can simply use http://www.rforge.net/audio, the code should look like this:

    # record 8000 samples at 8000Hz (1 sec), mono (1 channel)
    a <- record(8000, 8000, 1)
    wait(a) # wait for the recording to finish
    x <- a$data # get the result
    x[1:10] # show first ten samples
    #sample rate: 8000Hz, mono, 16-bits
    # [1] 0.018100981 0.017364085 0.016479610 0.013326526 0.010764275 0.011048204
    # [7] 0.010541249 0.010892886 0.007960078 0.006703259
    close(a); rm(a) # you can close the instance at this point
    play(x) # play back the result
    # amplify and crop the signal
    y <- x * 2
    y[y < -1] <- -1
    y[y > 1] <- 1
    # play the amplified signal
    play(y)
    

提交回复
热议问题