Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 下载mp3文件_R_Xml_List_Web_Rvest - Fatal编程技术网

R 下载mp3文件

R 下载mp3文件,r,xml,list,web,rvest,R,Xml,List,Web,Rvest,我想使用R的网站。该网站是我可以下载WAV的地方。包含给定文本和语言(语音)音频的文件 使用WAV下载语音有两个步骤: 1) 插入文本并选择语言。并提交 2) 在新窗口上,单击保存并选择文件夹 到目前为止,我可以获取xml树,将其转换为列表,并修改文本和语言的值。但是,我不知道如何将列表转换为XML(使用新值)并执行它。然后,我也需要做第二步 以下是我目前的代码: require(RCurl) require(XML) webpage <- getURL("http://soundofte

我想使用R的网站。该网站是我可以下载WAV的地方。包含给定文本和语言(语音)音频的文件

使用WAV下载语音有两个步骤: 1) 插入文本并选择语言。并提交 2) 在新窗口上,单击保存并选择文件夹

到目前为止,我可以获取xml树,将其转换为列表,并修改文本和语言的值。但是,我不知道如何将列表转换为XML(使用新值)并执行它。然后,我也需要做第二步

以下是我目前的代码:

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 
require(RCurl)
需要(XML)

网页我认为你的方法没有错,值得一试。。这也是我要写的。
这个页面有点烦人,因为它使用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')
库(httr)

url这里是文本声音的创建者。对不起,我花了这么长时间才找到这篇文章

我刚刚重新设计了文本的声音,所以您的html解析可能不再有效。 然而,现在有了一个API,您可以使用它使事情变得相当容易

您可以在此处找到文档:


如果不是很好,我道歉。如果您有任何问题,请告诉我。

您可能会在使用
rvest
软件包及其
html\u表单
功能时玩得更开心谢谢@GGamba。我用你的推荐修改了这篇文章。然而,它仍然不起作用。我做错了什么?再次感谢你@GGamba。它可以下载音频,但是,该文件没有长度,不能从任何播放器收听。有什么问题吗?抱歉,我还没有测试过。mp3文件所在的Url不同,请尝试以下操作:
download.file(URLencode(paste0http://soundoftext.com/static/sounds/,fd[['lang']],'/',fd[['text']],'.mp3'),'test.txt')
!非常感谢。顺便问一下,你知道如何解决一些语言中常见的词吗?请考虑UpvoToIP不能打开URL’:http状态是“404未找到”。
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')