V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  xinmans  ›  全部回复第 12 页 / 共 20 页
回复总数  392
1 ... 4  5  6  7  8  9  10  11  12  13 ... 20  
207 天前
回复了 xinmans 创建的主题 Mac Pro 有一台 macpro , intel 芯片的,开不了机
@linksNoFound 直接去 apple 体验店? 不知道是不是过保了
207 天前
回复了 xinmans 创建的主题 Mac Pro 有一台 macpro , intel 芯片的,开不了机
@julyclyde 我试试,好像可以。
207 天前
回复了 xinmans 创建的主题 Mac Pro 有一台 macpro , intel 芯片的,开不了机
@cssTheGreatest 我不在广深,邮寄靠谱不?
apple notes import 到 ob 出现很多问题,这个有好的 solution 吗? 之前一直用 applenotes 记录,你懂的,笔记杂乱
207 天前
回复了 chenzw2 创建的主题 分享创造 写给孙子玩的视觉错觉可视化
哈哈哈,年代感
@avenger 我也是。 不过我要尝试下 ob+icloud 同步
@frankyzf cool,还有其他的吗?
210 天前
回复了 gzk329 创建的主题 Kubernetes 有什么最稳妥的 K8s 部署方法吗?
r3d
最好是有个地下室或者储藏室,可以不用考虑噪音,否则可选的不多的。
211 天前
回复了 xinmans 创建的主题 问与答 有没有字幕翻译开源程序?
借助 chatgpt ,完美实现我的需求。

pip install googletrans==3.1.0a0

要实现将 a.en.srt 文件中的英文翻译成中文,并生成 b.cn.srt 和 c.en_cn.srt 文件,可以使用`googletrans`库来进行翻译。以下是一个示例代码,可以帮助你完成这个任务:

```python
from googletrans import Translator

def translate_text(text, target_language):
translator = Translator()
translation = translator.translate(text, dest=target_language)
return translation.text

def translate_srt(input_file, output_file, target_language):
with open(input_file, 'r') as file:
lines = file.readlines()

translated_lines = []
for line in lines:
line = line.strip()
if line.isdigit() or '-->' in line:
translated_lines.append(line)
elif line:
translated_text = translate_text(line, target_language)
translated_lines.append(translated_text)

with open(output_file, 'w') as file:
file.write('\n'.join(translated_lines))

# 翻译英文到中文
input_file = 'a.en.srt'
output_file_cn = 'b.cn.srt'
translate_srt(input_file, output_file_cn, 'zh-cn')

# 生成双字幕文件
output_file_en_cn = 'c.en_cn.srt'
with open(input_file, 'r') as file:
lines = file.readlines()

double_subtitles = []
for i in range(len(lines)):
line = lines[i].strip()
if line.isdigit() or '-->' in line:
double_subtitles.append(line)
elif line:
translated_text = translate_text(line, 'zh-cn')
double_subtitles.append(line)
double_subtitles.append(translated_text)

with open(output_file_en_cn, 'w') as file:
file.write('\n'.join(double_subtitles))
```

请确保在运行代码之前已经安装了`googletrans`库(可以通过`pip install googletrans==4.0.0-rc1`进行安装)。

代码中的`translate_text`函数用于将文本翻译成目标语言,`translate_srt`函数用于翻译整个 SRT 文件,并将结果写入输出文件。首先,我们使用`translate_srt`函数将英文翻译成中文,并将结果写入`b.cn.srt`文件。接下来,我们生成双字幕文件`c.en_cn.srt`,其中包含原始英文和翻译后的中文。

请注意,由于`googletrans`库依赖于 Google Translate 的 API ,翻译的准确性和可用性可能会受到限制。此外,使用自动翻译工具翻译长篇文本时,可能需要考虑分段和限制翻译频率,以避免超过 API 的使用限制。

c.en_cn.srt
1
00:00:00,041 --> 00:00:00,667
A spokesman for the
发言人
2
00:00:00,667 --> 00:00:02,127
Israeli Defense Forces.
以色列国防军。
3
00:00:02,127 --> 00:00:03,336
The top spokesperson
最高发言人
4
00:00:03,336 --> 00:00:04,295
says that it will start
说它将开始
211 天前
回复了 xinmans 创建的主题 问与答 有没有字幕翻译开源程序?
@haha512 谢谢,我只需要其中一部分自己包一下就能用了,多谢。

sp.py

from googletrans import Translator


text = f"{text.capitalize()}. " # .decode('utf-8').encode('gbk')
try:
#################### modify src='ja', dest="zh-cn" to define the source and target language ##########
## You can find all the possible language here:
# https://py-googletrans.readthedocs.io/en/latest/#googletrans-languages
# google 翻译
transd = translator.translate(text, src=video_config['source_language'],
dest=video_config['target_language']) # en zh-cn
result = transd.text # .decode('utf-8').encode('gbk')
except Exception as e:
print("Translate Error:", str(e))
continue


translator = Translator(service_urls=['translate.googleapis.com'])
r = sr.Recognizer()

# subtitles
if video_config['subtitle_out']=='双字幕':
combo_txt = text + '\n' + result + '\n\n'
else:
combo_txt = result + '\n\n'
if buffered:
# start_time += 2000
end_time -= 2000
start = timedelta(milliseconds=start_time)
end = timedelta(milliseconds=end_time)

index = len(subs) + 1
sub = srt.Subtitle(index=index, start=start, end=end, content=combo_txt)
subs.append(sub)

# whole_text += text
# whole_trans += result

final_srt = srt.compose(subs)
# todo 字幕合并
with open(sub_name, 'w', encoding="utf-8") as f:
f.write(final_srt)
qu.put(f" [get_large_audio_transcription] 生成字幕文件:final_str")
else:
qu.put(f"字幕文件已存在,直接使用 {sub_name=}")
updatebtn(mp4name, "开始合成字幕")
212 天前
回复了 xinmans 创建的主题 问与答 有没有字幕翻译开源程序?
20231022 - CNN forensic analysis suggests what may have caused Gaza hospital bla.description'
'20231022 - CNN forensic analysis suggests what may have caused Gaza hospital bla.en.srt'
'20231022 - CNN forensic analysis suggests what may have caused Gaza hospital bla.mp4'
'20231022 - CNN forensic analysis suggests what may have caused Gaza hospital bla.webp'


字幕节选
176
00:04:23,696 --> 00:04:25,098
This is going to be a difficult,

177
00:04:25,098 --> 00:04:26,032
difficult fight.

178
00:04:26,032 --> 00:04:26,833
All right, Spider,

179
00:04:26,833 --> 00:04:27,967
thank you so much

180
00:04:27,967 --> 00:04:29,469
for explaining all this.

181
00:04:29,469 --> 00:04:31,471
Don't go far because obviously,

182
00:04:31,471 --> 00:04:32,805
you know, more things could be happening

183
00:04:32,805 --> 00:04:34,540
very, very soon. Thank you very much.
写了一个脚本实现我需要的能力



#!/bin/sh


check_node_availability() {
local url=$1
response=$(curl -s -I "$url")
if echo "$response" | grep -q "200 OK"; then
echo "$url is accessible"
return 0
else
echo "$url is not accessible"
return 1
fi
}

check_url() {
success_count=0
for _ in 1 2 3
do
if check_node_availability "https://github.com"; then
success_count=$((success_count + 1))
fi
wait
sleep 3
done
return "$success_count"
}

while :
do
# 只在美国和英国节点间切换 tail -10
for node_id in `uci export passwall | grep 'config nodes' | tail -10 | awk '{print $3}'`; do
eval "i=${node_id}"
uci delete passwall.@global[0].tcp_node
wait
uci add_list passwall.@global[0].tcp_node=${i}
uci show passwall.@global[0].tcp_node
wait
uci commit passwall
wait
/etc/init.d/passwall restart
wait
sleep 10
while :
do
success_count=$(check_url)
if [ "$success_count" -ne 3 ]; then
echo "Switching to another node..."
break
else
sleep 600
fi
done
done
done
@flynaj nwan3 略显复杂啊,我还是自己写自己来切换吧
212 天前
回复了 xinmans 创建的主题 问与答 有没有字幕翻译开源程序?
可以 ffmpeg 提取
212 天前
回复了 xinmans 创建的主题 问与答 有没有字幕翻译开源程序?
@rimutuyuan 有英文字幕文件
212 天前
回复了 xinmans 创建的主题 问与答 有没有字幕翻译开源程序?
@rimutuyuan 第三方免费翻译 API 有哪些? Google 翻译?
212 天前
回复了 xinmans 创建的主题 问与答 有没有字幕翻译开源程序?
@qsmd42 我是下载到本地的,所以如果没有默认的字幕文件而是实时翻译的,是没有办法一起下载的
214 天前
回复了 MRG0 创建的主题 程序员 推荐个男士双肩包吧, ja 人们
tumi
@TinyBBC 有好的鸡场可以推荐给我
1 ... 4  5  6  7  8  9  10  11  12  13 ... 20  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1290 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 36ms · UTC 23:29 · PVG 07:29 · LAX 16:29 · JFK 19:29
Developed with CodeLauncher
♥ Do have faith in what you're doing.