Download mp3 file

I would like to use the website from R. The website is http://soundoftext.com/ , where I can download WAV. files with audio files from the specified text and language (voice).

There are two ways to load voice into WAV: 1) Paste text and select a language. And send 2) In the new window, click "Save" and select a folder.

So far, I could get the xml tree, convert it to a list, and change the text and language values. However, I do not know how to convert the list to XML (with new values) and execute it. Then I will need to take the second step.

Here is my code:

require(RCurl)
require(XML)
webpage <- getURL("http://soundoftext.com/")
webpage <- readLines(tc <- textConnection(webpage)); close(tc)
pagetree <- htmlTreeParse(webpage, error=function(...){}, useInternalNodes = TRUE)
x<-xmlToList(pagetree)
# Inserting word
x$body$div$div$div$form$div$label$.attrs[[1]]<-"Raúl"
x$body$div$div$div$form$div$label$.attrs[[1]]

# Select language
x$body$div$div$div$form$div$select$option$.attrs<-"es"
x$body$div$div$div$form$div$select$option$.attrs 

I follow this , but there is an error with the "tag".

: rvest , . ()?

url <- "http://soundoftext.com/"
s <- html_session(url)
f0 <- html_form(s)
f1 <- set_values(f0[[1]], text="Raúl", lang="es")
attr(f1, "type") <- "Submit"
s[["fields"]][["submit"]] <- f1
attr(f1, "Class") <- "save"

test <- submit_form(s, f1)
+4
2

, . , .
, jquery div. , rvest, , httr:

library(httr)    

url <- "http://soundoftext.com/sounds"

fd <- list(
  submit = "save",
  text = "Banana", 
  lang="es"
)

resp<-POST(url, body=fd, encode="form")
id <- content(resp)$id

download.file(URLencode(paste0("http://soundoftext.com/sounds/", id)), destfile = 'test.mp3')

, POST , ID, GET, ID, .

+1

. , , .

Sound of Text, html, , . , API, , .

: https://soundoftext.com/docs

, . , , .

0

Source: https://habr.com/ru/post/1669847/


All Articles