为什么在使用for循环时gl_speech返回错误,但对于每个单独的文件却不返回错误?使用tryCatch

如何解决为什么在使用for循环时gl_speech返回错误,但对于每个单独的文件却不返回错误?使用tryCatch

我最近才开始使用R和googleLanguageR软件包-太好了!

我想使用gl_speech将400多个.flac文件(每个文件约20秒)转换为文本。

我编写了以下循环:


    for (i in files) {
      possibleError <- tryCatch({ 
        participantid = str_sub(i,1,3)
        patha = paste(path_in,i,sep='')
        result <- gl_speech(patha,sampleRateHertz = 44100L,customConfig = my_config)
        transcript2 <- subset(result$transcript,select=-c(languageCode,channelTag))
        transcriptid <- cbind(participantid,transcript2)
        write_delim(as.data.frame(transcriptid),file.path(path_in,paste0(participantid,'_text.csv')))
      },error = function(e) e)
      
        if(inherits(possibleError,"error"))  next 
      
        }

为完整起见,my_config为:


    my_config <- list(audioChannelCount = 2,encoding = "FLAC",maxAlternatives = 30,languageCode = "en-US",model = "video"
    )

我一次要处理2、5或10个文件。其中一些返回错误错误消息是:


    ℹ 2020-10-08 20:07:56 > Request Status Code:  408
    Error : lexical error: invalid char in json text.
                                           <!DOCTYPE html> <html lang=en> 
                         (right here) ------^
    
    <!DOCTYPE html>
    <html lang=en>
      <Meta charset=utf-8>
      <Meta name=viewport content="initial-scale=1,minimum-scale=1,width=device-width">
      <title>Error 408 (Request Timeout)!!1</title>
      <style>
        *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
      </style>
      <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
      <p><b>408.</b> <ins>That’s an error.</ins>
      <p>Your client has taken too long to issue its request.  <ins>That’s all we kNow.</ins>

但是,当我以后运行分别返回错误文件时,gl_speech不会返回此错误

是否有另一种方法来循环处理多个文件,从而避免了那么多错误

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?