# Scrapes audio from https://chinese.yabla.com/chinese-pinyin-chart.php

setwd("C:/Users/nesau/Desktop/ToneChart")
toneChart <- read.csv("ToneChart.csv")
toneChart <- toneChart[,-1]

baseURL <- "http://d2mllj54g854r4.cloudfront.net/chinese_static/audio/alicia/"
extension <- ".mp3"

getAudio <- F

if (getAudio)
{
  for (row in 1:nrow(toneChart))
  {
    for (col in 1:ncol(toneChart))
    {
      char <- toneChart[row,col]
      
      if(char != "")
      {
        for (tone in 1:4)
        {
          url <- paste0(baseURL, char, tone, extension)
          url <- gsub("ΓΌ", "v", url)
          download.file (url, destfile = paste0("audio/", char, tone, extension))
        }
      }
    }
  }
}