writing wav-file in shiny app with seewave and tuneR

99封情书 提交于 2020-01-16 03:59:07

问题


I have a shiny app with a number of tabPanels. In one of these panels I want to write a time signal generated in seewave and tuneR to a www subdirectory. If I run the commands on the R-promt, everything works, but I can't get it running in my server.R. I tried observe, but then the input$ variables are not updated:

observeEvent(input$button,{
        cat("Writing wav file")
})
eventReactive(input$button,{
        "Inbutton"
        pi<-4*atan(1)
        s5<-synth(44100,5,input$freq1,input$amp1*2000,"sine",shape=NULL,p=0,
                 am=c(0,0,0),fm=c(0,0,0),harmonics=1,plot=FALSE,output="Wave")
        s6<-synth(44100,5,input$freq2,input$amp2*2000,"sine",shape=NULL,
                  p=input$phase/180*pi,am=c(0,0,0),fm=c(0,0,0),
                  harmonics=1,plot=FALSE,output="Wave")
        s7<-s5+s6  
        str(s7)
        Wobj<-s7
        wav_dir<-"./www"
        wav_file<-file.path(wav_dir,"howling2.wav")
        writeWave(Wobj,filename=wav_file)
        play(s7)
})

回答1:


I've managed somehow to save the file. I defined function that generates the sound and load it beforehand. Then in server function I call it like that:

server <- function(input, output){  

  observeEvent(input$button, {
  sound <- sonify(input$name) # this is already a Wave object

  wvname <- paste0("sound", input$button,".wav")
  writeWave(sound, paste0("www/", wvname))

  })

}

Then to implement it in UI follow this and this



来源:https://stackoverflow.com/questions/33594007/writing-wav-file-in-shiny-app-with-seewave-and-tuner

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!