import os
import subprocess
from gtts import gTTS
class Record:
def __init__(self, file, path):
self.file_name = f'{file.split(".")[0]}.mp3'
self.file_path = os.path.join(path, file)
self.out_path = os.path.join(path, self.file_name)
def create_recordings(self):
subprocess.call(['gtts-cli', '-f' + self.file_path, '-o' + self.out_path])
path = r'C:\Users\xxxx\Desktop\create_recordings'
for file in os.listdir(path):
if file.endswith('.txt'):
Record(file, path).create_recordings()
我正在尝试做什么:
更改subprocess.call命令中的语言 香港专业教育学院尝试在self.file_path之后添加'lang ='+'en-uk',但返回错误:
Usage: gtts-cli [OPTIONS] <text>
Error: Invalid value for "<text>": <text> and -f/--file <file> can't be used together
所以我不太确定如何更改它以添加其他语言
如果我可以将语言传递给Record类并在subprocess.call命令中使用该语言,那么真正的ID是
有很多语言可以将其更改为,但是这里是在命令行中使用gtts-cli --all显示的所有英文:
en-au: English (Australia)
en-ca: English (Canada)
en-gb: English (UK)
en-gh: English (Ghana)
en-ie: English (Ireland)
en-in: English (India)
en-ng: English (Nigeria)
en-nz: English (New Zealand)
en-ph: English (Philippines)
en-tz: English (Tanzania)
en-uk: English (UK)
en-us: English (US)
en-za: English (South Africa)