Sample file

Init

filename <- "audiosample.wav" # select file

library(tuneR)
library(seewave)
library(ggplot2)
library(plotly)

Read *.wav

d <- readWave(filename)
d
## 
## Wave Object
##  Number of Samples:      617800
##  Duration (seconds):     14.01
##  Samplingrate (Hertz):   44100
##  Channels (Mono/Stereo): Mono
##  PCM (integer format):   TRUE
##  Bit (8/16/24/32/64):    16

Plot raw data

# get  audio data
amp <- d@left

# get audio length
sound_length <- round(length(amp) / d@samp.rate) 

# simply skip frames to plot faster
skip = 100 # skips 99 frames

# create time vector
t <- seq(from=0,
         to=sound_length,
         length.out=length(amp))

audio <- data.frame(t=t,amp = amp)

audio_skipped <- audio[seq(from=1,
                           to= length(amp),
                           by=skip),]

# plot
p<-ggplot(audio_skipped,aes(x=t,y=amp))+
  geom_path()
p

# interactive version
# ggplotly(p)

Cut

tbegin <- 9
tend   <- 10.5

# check plot
oscillo(d,
        from=tbegin,
        to=tend,
        fastdisp = 1)

Detect frequency peaks

# return the mean frequency spectrum
spec <- meanspec(d,   
                 wl=512, # window length of the analysis, even number
                 wn = "hanning", # window name
                 norm=TRUE, # normalised by its maximum
                 f=d@samp.rate, # sampling frequency of wave (in Hz).
                 from = tbegin, # start point in s
                 to = tend, # end mark in s
                 channel = 1,
                 plot=FALSE)
fpeaks(spec,
       nmax=3, # n highest peaks
       ylim=c(0,1.1),
       digits=4 # decimal places
       )

Interactive frequency detection

library(plotly)


df<-as.data.frame(spec)


y_maxy <- max(df$y)
x_maxy <- df[which(df$y==max(df$y)),"x"]
            
p<-ggplot(df,aes(x=x,y=y))+
  geom_line()+
  geom_text(x = x_maxy,
            y = y_maxy,
            label=as.character(round(x_maxy,digits=4)),
            hjust =-1 )

p 

# interactive version
# ggplotly(p)

Compare results with Audacity