• praat 脚本出错(提取textgrid中所标注的特定部分并存入新建文件夹,最后删除空的新建文件夹)


    关注 码龄 粉丝数 原力等级 -- 被采纳 被点赞 采纳率 2301_79876310 2024-04-04 15:59 采纳率: 0% 浏览 3 首页/ 微软技术 / praat 脚本出错(提取textgrid中所标注的特定部分并存入新建文件夹,最后删除空的新建文件夹) windows语音识别 删除文件夹命令 deleteDirectory(new_dir$)无法运行 Windows系统 1. 在原文件夹中创建和录音名称相同的新文件夹; 2. 在textgrid文件中提取标签为“t“的intervals; 3. 将提取好的文件放入新的文件夹中; 4. 检查新创立的文件夹是否为空,若为空,则删除文件夹。 form Extract smaller files from large file sentence Directory: D:\Praat\Testing_data sentence File_prefix: phoneme_ positive Tier_number: 1 endform clearinfo string = Create Strings as file list: "filelist", directory$ + "\*.wav" select 'string' num_file = Get number of strings for i_file to num_file select 'string' file_name$ = Get string: i_file Read from file: directory$ + "\" + file_name$ sound_file = selected("Sound") sound_name$ = selected$("Sound") new_dir$ = directory$ + "\" + sound_name$ createDirectory(new_dir$) printline New directory "'new_dir$'" has created. Read from file: directory$ + "\" + sound_name$ + ".TextGrid" textgrid_file = selected("TextGrid") select 'textgrid_file' num_intvl = Get number of intervals: tier_number printline Totally 'num_intvl' intervals in tier 'tier_number'. for i_intvl to num_intvl select 'textgrid_file' lab$ = Get label of interval: tier_number, i_intvl if lab$ = "t" printline Start working on interval No.'i_intvl', "'lab$'". start = Get start time of interval: tier_number, i_intvl end = Get end time of interval: tier_number, i_intvl select 'textgrid_file' textgrid_chunk = Extract part: start, end, "no" select 'sound_file' Extract part: start, end, "rectangular", 1, "no" Write to WAV file: new_dir$ + "\" + file_prefix$ + lab$ + ".wav" select 'textgrid_chunk' Save as text file: new_dir$ + "\" + file_prefix$ + lab$ + ".TextGrid" else endif endfor new_string = Create Strings as file list: "list", new_dir$ num_string = Get number of strings if num_string = 0 printline No files found in the directory. deleteDirectory(new_dir$) printline 'new_dir$' has been removed else printline Directory contains files endif endfor select all Remove printline already! 展开全部 收起 写回答 好问题 0 提建议 追加酬金 关注问题 微信扫一扫 点击复制链接 分享 邀请回答 编辑 收藏 删除 结题 收藏 举报 追加酬金 (90%的用户在追加酬金后获得了解决方案) 当前问题酬金 ¥ 0 (可追加 ¥500) ¥ 15¥ 20¥ 50¥ 100¥ 200 支付方式 扫码支付 二维码出错 点击刷新 支付金额 15 元 提供问题酬金的用户不参与问题酬金结算和分配 支付即为同意 《付费问题酬金结算规则》 结题 再想想 删除 再等等

    3条回答 默认 最新

    • Kwan的解忧杂货铺 Java领域优质创作者 2024-04-04 15:59
      关注

      下午好🌅🌅🌅
      本答案参考ChatGPT-3.5

      对于此问题,您遇到了两个错误。第一个是删除文件夹命令的错误,第二个是判断新建文件夹是否为空的错误。

      针对这两个问题,您可以按照以下步骤进行修改:

      1. 将deleteDirectory(new_dir$)替换为removeDirectory(new_dir$)或dropDirectory(new_dir$),这两个命令是删除文件夹的有效命令。

      2. 在判断新建文件夹是否为空时,您可以使用创建一个字符串列表,然后通过获取列表中的字符串数量来判断文件夹是否为空。如果数量为0,则表示文件夹为空,可以调用removeDirectory(new_dir$)或dropDirectory(new_dir$)删除文件夹。如果数量不为0,则表示文件夹中有文件,可以继续操作。

      根据上述修改,您的修改后的代码如下:

      form Extract smaller files from large file
        sentence Directory: D:\Praat\Testing_data
        sentence File_prefix: phoneme_
        positive Tier_number: 1
      endform
      
      clearinfo
      
      string = Create Strings as file list: "filelist", directory$ + "\*.wav"
      select 'string'
      num_file = Get number of strings
      
      for i_file to num_file
        select 'string'
        file_name$ = Get string: i_file 
        Read from file: directory$ + "\" + file_name$
        sound_file = selected("Sound")
        sound_name$ = selected$("Sound")
        new_dir$ = directory$ + "\" + sound_name$
        createDirectory(new_dir$)
        printline New directory "'new_dir$'" has created.
        
        Read from file: directory$ + "\" + sound_name$ + ".TextGrid"
        textgrid_file = selected("TextGrid")
        select 'textgrid_file'
        num_intvl = Get number of intervals: tier_number
        printline Totally 'num_intvl' intervals in tier 'tier_number'. 
        
        for i_intvl to num_intvl
          select 'textgrid_file'
          lab$ = Get label of interval: tier_number, i_intvl
          if lab$ = "t"
            printline Start working on interval No.'i_intvl', "'lab$'".
      
            start = Get start time of interval: tier_number, i_intvl
            end = Get end time of interval: tier_number, i_intvl
            select 'textgrid_file'
            textgrid_chunk = Extract part: start, end, "no"
            select 'sound_file'
            Extract part: start, end, "rectangular", 1, "no"
            Write to WAV file: new_dir$ + "\" + file_prefix$ + lab$ + ".wav"
            select 'textgrid_chunk'
            Save as text file: new_dir$ + "\" + file_prefix$ + lab$ + ".TextGrid"
          else
          
          endif
      
        endfor
          
        new_string = Create Strings as file list: "list", new_dir$
        num_string = Get number of strings
      
        if num_string = 0
          printline No files found in the directory. 
          removeDirectory(new_dir$) ; 或 dropDirectory(new_dir$)
          printline 'new_dir$' has been removed
        else
          printline Directory contains files
        endif
      
      endfor
      
      select all
      Remove
      
      printline already!
      

      希望这些修改可以解决您的问题。如果还有其他问题,请随时向我咨询。

      展开全部

      评论 编辑记录
    • 专家-赤兔[在线] 全栈领域优质创作者 2024-04-04 15:59
      关注

      问题: praat 脚本出错(提取textgrid中所标注的特定部分并存入新建文件夹,最后删除空的新建文件夹)

      内容: 删除文件夹命令 deleteDirectory(new_dir$)无法运行 Windows系统 无效:将deleteDirectory(new_dir$)替换成removeDirectory(new_

      下方内容正在编辑完善中,如有疑问请回复我,如问题解决,请采纳,感谢!

      评论
      2301_79876310 2024-04-04 17:32

      remove drop delete 都无效

      回复
    • GISer Liu 2024-04-04 16:05
      关注

      该回答引用自GPT-3.5,由博主GISer Liu编写:

      根据问题描述,你的目标是从大型文件中提取特定标签的部分,并将其保存到新建文件夹中,最后删除空的新建文件夹。下面是你的解决思路和解决方案:

      1. 创建与录音名称相同的新文件夹
      • 在循环中,使用createDirectory(new_dir$)创建新文件夹。
      1. 提取标签为“t”的intervals
      • 使用Get label of interval: tier_number, i_intvl获取标签,判断是否为"t"。
      1. 将提取好的文件放入新的文件夹中
      • 在循环中,使用Write to WAV file将音频文件保存到新文件夹中。
      • 使用Save as text file将TextGrid文件保存到新文件夹中。
      1. 检查新创立的文件夹是否为空,若为空,则删除文件夹
      • 使用Create Strings as file list: "list", new_dir$获取新文件夹中的文件列表。
      • 使用Get number of strings获取文件数量,若为0,则删除文件夹。
        下面是修改后的代码,已经根据问题描述中的需求进行了修改:
        praatCopy code
        form Extract smaller files from large file
        sentence Directory: D:\Praat\Testing_data
        sentence File_prefix: phoneme_
        positive Tier_number: 1
        endform
        clearinfo
        string = Create Strings as file list: "filelist", directory$ + "\*.wav"
        select 'string'
        num_file = Get number of strings
        for i_file to num_file
        select 'string'
        file_name$ = Get string: i_file
        Read from file: directory$ + "\" + file_name$
        sound_file = selected("Sound")
        sound_name$ = selected$("Sound")
        new_dir$ = directory$ + "\" + sound_name$
        createDirectory(new_dir$)
        printline New directory "'new_dir$'" has been created.
        Read from file: directory$ + "\" + sound_name$ + ".TextGrid"
        textgrid_file = selected("TextGrid")
        select 'textgrid_file'
        num_intvl = Get number of intervals: tier_number
        printline Totally 'num_intvl' intervals in tier 'tier_number'.
        for i_intvl to num_intvl
        select 'textgrid_file'
        lab$ = Get label of interval: tier_number, i_intvl
        if lab$ = "t"
        printline Start working on interval No.'i_intvl', "'lab$'".
        start = Get start time of interval: tier_number, i_intvl
        end = Get end time of interval: tier_number, i_intvl
        select 'textgrid_file'
        textgrid_chunk = Extract part: start, end, "no"
        select 'sound_file'
        Extract part: start, end, "rectangular", 1, "no"
        Write to WAV file: new_dir$ + "\" + file_prefix$ + lab$ + ".wav"
        select 'textgrid_chunk'
        Save as text file: new_dir$ + "\" + file_prefix$ + lab$ + ".TextGrid"
        endif
        endfor
        new_string = Create Strings as file list: "list", new_dir$
        num_string = Get number of strings
        if num_string = 0
        printline No files found in the directory.
        removeDirectory(new_dir$)
        printline 'new_dir$' has been removed
        else
        printline Directory contains files
        endif
        endfor
        select all Remove
        printline already!
        
        注意,以上代码中的 removeDirectory(new_dir$) 可以用于删除空的新建文件夹。

      如果该回答解决了您的问题,请采纳!如果没有,请私信联系或评论您的疑惑

      展开全部

      评论
    编辑
    预览

    报告相同问题?

  • 相关阅读:
    从购买云服务器开始到成功部署网站并且可以正常外网访问整个体系流程(从0到1的过程)
    mysql表操作
    鸿鹄工程项目管理系统em Spring Cloud+Spring Boot+前后端分离构建工程项目管理系统
    mysql学习笔记1:忘记密码
    驱动开发:内核物理内存寻址读写
    eclipse中springboot项目如何打包成jar文件
    【强大的数据迁移和恢复解决方案】KernelApps及其产品介绍
    react中的this指向问题
    Kubernetes资源编排系列之四: CRD+Operator篇
    Oralce笔记-解决Oracle18c中ORA-28001: 口令已经失效
  • 原文地址:https://ask.csdn.net/questions/8083534