Hey,
I am new to the R Studio community and I am trying to create an app using Shiny. The app lets you play the sound file as chosen by the user and the user can also alter the pitch. For now, I have created the code for the sound to be played and the code for altering the pitch is still to be written.
Well, I am facing a problem in the following code:
ui.R
library(shiny)
library(shinydashboard)
library(readr)
library(tuneR)
library(seewave)
library(sound)
ui <- fluidPage(
titlePanel("Music Speed and Pitch Changer"),
sidebarLayout(
sidebarPanel(div(h4("Select a song"),style = "color: black;",
fileInput("file1","Choose File", multiple = F, accept = "audio/*")),
div(h4("Play"),style = "color: black;",
actionButton("play","Play")),
div(h4("Pitch"),style = "color: black;",
sliderInput("obs","Changes in semitones",min = -12.00, max = 12.00, value = 0.00),
div(p("A value smaller than zero means that the resulting key is lower than the original key (and vice-versa). A value of zero means that the key is not changed. One full step corresponds to one semitone. Decimals can be used for fine adjustments (for instance for non-western music styles). Example: a change of -12 semitones means that the song is played one octave lower."))),
#div(h4("Speed"),style = "color: black;"),
#sliderInput("obs","Change in tempo",min = 0.5, max = 2.0, value = 1),
#div(p(" 1.0 is he original tempo, 0.5 is half tempo, 2.0 is double tempo"))
),
mainPanel(div(h3("Output Song"),
actionButton("convert","convert")))
)
)
server.R
library(shiny)
#library(shinydashboard)
library(readr)
library(tuneR)
library(seewave)
library(sound)
server <- function(input, output) {
file <- reactive({file <- input$file1
file <- readMP3(file)
})
setWavPlayer("C:/Program Files/Windows Media Player/wmplayer.exe")
writeWave(file,"tmp.wav",extensible=FALSE)
tmp <- readWave("tmp.wav")
eventReactive(input$play, {
insertUI(selector = "#play",
where = "afterEnd",
ui = tags$audio(src = "tmp.wav", type = "audio/wav", autoplay = NA, controls = NA, style="display:none;"))
})
}
The error I am receiving on running the app:
Error in writeWave(file, "tmp.wav", extensible = FALSE) :
'object' needs to be of class 'Wave' or 'WaveMC'
Any help is much appreciated.
Thank You!