微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

text-processing – 将xml字幕文件转换为srt格式

我有一个xml字幕,如下所示:

<?xml version="1.0" encoding="utf-8" ?><transcript>
  <Item from="1.16" duration="4.68"><![CDATA[(Dong-hyuk is coming
to see you Now.)
]]></Item>
  <Item from="5.92" duration="1"><![CDATA[It's cold.
]]></Item>
  <Item from="9.04" duration="2.88"><![CDATA[- Hello.
- Hello.
]]></Item>
  <Item from="12.2" duration="1.76"><![CDATA[You're busy as always.
]]></Item>
  <Item from="14.04" duration="3.48"><![CDATA[Look what I have here. Ta-da!
]]></Item>
  <Item from="18.88" duration="1.5599999999999998"><![CDATA[Let me give it to you.
]]></Item>
  <Item from="20.919999999999998" duration="2.8"><![CDATA[I'll give you
the most valuable present...
]]></Item>
</transcript>

似乎“]]>< / Item>”总是传播到新的一行.
有没有办法将其转换为srt格式?

解决方法:

我使用像xsh这样的XML处理工具:

open subtitles.xml ;
for /transcript/Item {
    echo position() ;
    echo @from '-->' (@from + @duration) ;
    echo text() ;
}

输出

1
1.16 --> 5.84
(Dong-hyuk is coming
to see you Now.)

2
5.92 --> 6.92
It's cold.

3
9.04 --> 11.92
- Hello.
- Hello.

4
12.2 --> 13.96
You're busy as always.

5
14.04 --> 17.52
Look what I have here. Ta-da!

6
18.88 --> 20.44
Let me give it to you.

7
20.919999999999998 --> 23.72
I'll give you
the most valuable present...

转换时间数据留给读者练习.

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