0

What do you suggest I do to read metadata from MP3 files created with Audacity?

I routinely use R with RStudio. A previous post to StackOverflow asked, ""Is it possible to read music file metadata using R?" Someone said 'You "could" use a combination of readChar and / or readBin. I tried

data<- readBin(MP3file, 'character', 30000)

I parsed "data", sort of, using rle(data == '') to differentiate between the ID3v2.3 and the actual sound data. However, what I got did not seem very informative.

I found other discussions recommending taglib-sharp, e.g., "How to use taglib to get information from a audio file", but I could not see how to use that. I've seen other discussions recommending other things, other Python packages or C or C#. I've used Python a tiny bit but not enough to know what to do here.

Help. Thanks, Spencer Graves

Phil
  • 7,287
  • 3
  • 36
  • 66
  • Hi Spencer! Can you give an idea of what you want to see? – Mark Aug 10 '23 at 00:49
  • Closed as a duplicate: the previous question is old but does include answers that recommend `exiftool`, which is probably the preferred solution at present. – neilfws Aug 10 '23 at 01:24

2 Answers2

1

As suggested here, you can use exiftool (in this case, using exifr):

# download a public domain mp3 file from The Internet Archive
download.file("https://archive.org/download/Jazz_Sampler-9619/Kevin_MacLeod_-_AcidJazz.mp3", "jazz.mp3", mode = "wb")

install.packages("exifr") # if necessary

# read the exif data from it
exifr::read_exif("jazz.mp3")

# Output:
  SourceFile ExifToolVersion FileName Directory FileSize FileModifyDate         
  <chr>                <dbl> <chr>    <chr>        <int> <chr>                  
1 jazz.mp3              12.2 jazz.mp3 .          5090909 2023:08:10 14:53:41+14…
# ℹ 34 more variables: FileAccessDate <chr>, FileInodeChangeDate <chr>,
#   FilePermissions <int>, FileType <chr>, FileTypeExtension <chr>,
#   MIMEType <chr>, MPEGAudioVersion <int>, AudioLayer <int>,
#   AudioBitrate <int>, SampleRate <int>, ChannelMode <int>, MSStereo <int>,
#   IntensityStereo <int>, CopyrightFlag <int>, OriginalMedia <int>,
#   Emphasis <int>, ID3Size <int>, Title <chr>, Artist <chr>, Track <int>,
#   Album <chr>, RecordingTime <chr>, Genre <chr>, Copyright <chr>, …
Mark
  • 7,785
  • 2
  • 14
  • 34
1

You could look into exiftool which extracts metadata from a wide variety of media file formats, including MP3. It can generate CSV output and there are two R packages which use it: exiftoolr and exifr.

Example usage - with exiftool installed and in your path, from a command-prompt or terminal:

exiftool -csv yourfile.mp3 > yourfile.csv

And then read the CSV file into R using e.g. read.csv() or readr::read_csv().

With exifr installed you might do something like this (untested):

library(exifr)

files <- list.files("path/to/your/mp3files", 
                    recursive = TRUE, 
                    pattern = "*.mp3", 
                    full.names = TRUE)

metadata <- read_exif(files)

Similarly with exiftoolr installed (untested):

library(exiftoolr)

files <- list.files("path/to/your/mp3files", 
                    recursive = TRUE, 
                    pattern = "*.mp3", 
                    full.names = TRUE)

metadata <- exif_read(files, pipeline = "csv")
neilfws
  • 32,751
  • 5
  • 50
  • 63
  • 1
    ah curses I just got in there before you ^_^ – Mark Aug 10 '23 at 01:02
  • 1
    You were first! I hope our answers are complementary, rather than mine just being a duplicate :) – neilfws Aug 10 '23 at 01:03
  • re: exifr vs exiftoolr, I seem to remember reading that one of them used system(), and the other used system2(), with system2 being better, but I can't seem to find any mention of this anywhere now – Mark Aug 10 '23 at 01:05
  • 1
    tbh I think this whole question is a duplicate of https://stackoverflow.com/questions/3390262/is-it-possible-to-read-music-file-metadata-using-r/ – Mark Aug 10 '23 at 01:06