首页 文章

R中的录音

提问于
浏览
1

我在R for Windows中玩一些音频和声音包(我的是Win7 x64) . 我尝试使用record()从麦克风录制时出现问题:

  • 它只能记录一次然后再记录一些,直到重启整个控制台

  • 一旦录制声音,它可以保存但不能播放()
    从上面录制的

  • 文件无法通过音频读取,但是由于'incomplete wave file'而调整了

  • 以及以下“文件名”不起作用

filename = paste0('abcd',' . wav')save.wave(x,filename)

直到直接输入命令为止,这使得编写记录脚本/函数变得困难

save.wave(x,'abc.wav')

我想问任何人在Win和另一个操作系统中使用音频包,如果你遇到同样的问题 . 谢谢 .

2 回答

  • 0

    你可以简单地使用http://www.rforge.net/audio,代码应如下所示:

    # 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)
    
  • 1

    我刚写了一个记录功能 . 它工作但运行一段时间后,程序必须关闭,然后再次打开R:

    audiorec=function(kk,f){  # kk: time length in seconds; f: filename
    if(f %in% list.files()) 
    {file.remove(f); print('The former file has been replaced');}
    require(audio)
    s11 <- rep(NA_real_, 16000*kk) # rate=16000
    record(s11, 16000, 1)  # record in mono mode
    wait(kk)
    save.wave(s11,f)
    }
    

    仍然是GUI的问题 . 我尝试使用Win7的其他计算机,但遇到了同样的错误 . 有一些错误,我还没弄明白 .

相关问题