# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .r
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: R
#     language: R
#     name: ir
# ---

# ## Converting Mp3 to wav format
#
# This notebook has written in R-language. To run this notebbok you need to select R-Kernel

library(tuneR)

# reading data from a folder 
file_list <- list.files(path = "./Deezer Data/artist/mp3/", pattern = NULL, all.files = FALSE,
           full.names = FALSE, recursive = FALSE,
           ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)
length(file_list)

# converting mp3 to wav
for (file in file_list){
    src <- paste('./Deezer Data/artist/mp3/', file, sep='')
    desc <- paste('./Deezer Data/artist/wav/', substr(file, 1 , nchar(file)-4), '.wav', sep='')
    r <- readMP3(src)  ## MP3 file in working directory
    writeWave(r,desc,extensible=FALSE)
}

# read the file in wav folder and display count
file_list_wav <- list.files(path = "./Deezer Data/artist/mp3/", pattern = NULL, all.files = FALSE,
           full.names = FALSE, recursive = FALSE,
           ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)
length(file_list_wav)

# ## Converting Mp4 to wav

#install.packages("av")
library(av)

# ### JioSaaven - English

# ### Genre: Converting mp4 to wav format  

# reading data from a folder 
file_list <- list.files(path = "./JioSavan Data/English/genre/mp4/", pattern = NULL, all.files = FALSE,
           full.names = FALSE, recursive = FALSE,
           ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)
length(file_list)

# converting mp3 to wav
for (file in file_list){
    src <- paste('./JioSavan Data/English/genre/mp4/', file, sep='')
    desc <- paste('./JioSavan Data/English/genre/wav/', substr(file, 1 , nchar(file)-4), '.wav', sep='')
    try(av_audio_convert(src, desc))
}

file_list_wav <- list.files(path = "./JioSavan Data/English/genre/wav/", pattern = NULL, all.files = FALSE,
           full.names = FALSE, recursive = FALSE,
           ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)
length(file_list_wav)

# ### Artist: Converting mp4 to wav format  

# reading data from a folder 
file_list <- list.files(path = "./JioSavan Data/English/artist/mp4/", pattern = NULL, all.files = FALSE,
           full.names = FALSE, recursive = FALSE,
           ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)
length(file_list)

# converting mp3 to wav
for (file in file_list){
    src <- paste('./JioSavan Data/English/artist/mp4/', file, sep='')
    desc <- paste('./JioSavan Data/English/artist/wav/', substr(file, 1 , nchar(file)-4), '.wav', sep='')
    av_audio_convert(src, desc)
}

file_list_wav <- list.files(path = "./JioSavan Data/English/artist/wav/", pattern = NULL, all.files = FALSE,
           full.names = FALSE, recursive = FALSE,
           ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)
length(file_list_wav)

# ### JioSaaven - Telugu

# ### Genre: Converting mp4 to wav format  

# reading data from a folder 
file_list <- list.files(path = "./JioSavan Data/Telugu/genre/mp4/", pattern = NULL, all.files = FALSE,
           full.names = FALSE, recursive = FALSE,
           ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)
length(file_list)

# converting mp3 to wav
for (file in file_list){
    src <- paste('./JioSavan Data/Telugu/genre/mp4/', file, sep='')
    desc <- paste('./JioSavan Data/Telugu/genre/wav/', substr(file, 1 , nchar(file)-4), '.wav', sep='')
    try(av_audio_convert(src, desc))
}

file_list_wav <- list.files(path = "./JioSavan Data/Telugu/genre/wav/", pattern = NULL, all.files = FALSE,
           full.names = FALSE, recursive = FALSE,
           ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)
length(file_list_wav)

# ### Artist: Converting mp4 to wav format  

# reading data from a folder 
file_list <- list.files(path = "./JioSavan Data/Telugu/artist/mp4/", pattern = NULL, all.files = FALSE,
           full.names = FALSE, recursive = FALSE,
           ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)
length(file_list)

# converting mp3 to wav
for (file in file_list){
    src <- paste('./JioSavan Data/Telugu/artist/mp4/', file, sep='')
    desc <- paste('./JioSavan Data/Telugu/artist/wav/', substr(file, 1 , nchar(file)-4), '.wav', sep='')
    av_audio_convert(src, desc)
}

file_list_wav <- list.files(path = "./JioSavan Data/Telugu/artist/wav/", pattern = NULL, all.files = FALSE,
           full.names = FALSE, recursive = FALSE,
           ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)
length(file_list_wav)

# ### JioSaaven - Hindi
#
# ### Genre: Converting mp4 to wav format  

# reading data from a folder 
file_list <- list.files(path = "./JioSavan Data/Hindi/genre/mp4/", pattern = NULL, all.files = FALSE,
           full.names = FALSE, recursive = FALSE,
           ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)
length(file_list)

# converting mp3 to wav
for (file in file_list){
    src <- paste('./JioSavan Data/Hindi/genre/mp4/', file, sep='')
    desc <- paste('./JioSavan Data/Hindi/genre/wav/', substr(file, 1 , nchar(file)-4), '.wav', sep='')
    try(av_audio_convert(src, desc))
}

file_list_wav <- list.files(path = "./JioSavan Data/Hindi/genre/wav/", pattern = NULL, all.files = FALSE,
           full.names = FALSE, recursive = FALSE,
           ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)
length(file_list_wav)

# ### Artist: Converting mp4 to wav format  

# reading data from a folder 
file_list <- list.files(path = "./JioSavan Data/Hindi/artist/mp4/", pattern = NULL, all.files = FALSE,
           full.names = FALSE, recursive = FALSE,
           ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)
length(file_list)

# converting mp3 to wav
for (file in file_list){
    src <- paste('./JioSavan Data/Hindi/artist/mp4/', file, sep='')
    desc <- paste('./JioSavan Data/Hindi/artist/wav/', substr(file, 1 , nchar(file)-4), '.wav', sep='')
    av_audio_convert(src, desc)
}

file_list_wav <- list.files(path = "./JioSavan Data/Hindi/artist/wav/", pattern = NULL, all.files = FALSE,
           full.names = FALSE, recursive = FALSE,
           ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)
length(file_list_wav)



StarcoderdataJupyterScriptsDedupFiltered