Python gtts 语言检测
Python gtts language detection
大家好,我在多语言社交网络上工作,我想添加一个选项来收听 post 作为音频我尝试使用 python 进行 gtts,我只是想问一下是否有是一种自动检测语言的方法。
我打算在 python 中使用一个名为 googletrans 的模块来检测 post 的语言,然后在不翻译的情况下阅读它,但我觉得这不是最好的解决方案。
如果您提供任何帮助,我将不胜感激:)
您可以使用 textblob
检测语言:pip install textblob
from textblob import TextBlob
b = TextBlob("bonjour")
text = b.detect_language()
然后用pyttsx3
大声朗读:
pip install pyttsx3
import pyttsx3
engine = pyttsx3.init() # object creation
rate = engine.getProperty('rate') # getting details of current speaking rate
print (rate) #printing current voice rate
engine.setProperty('rate', 125) # setting up new voice rate
voices = engine.getProperty('voices') #getting details of current voice
#engine.setProperty('voice', voices[0].id) #changing index, changes voices. o for male
engine.setProperty('voice', voices[1].id) #changing index, changes voices. 1 for female
engine.say(text)
engine.save_to_file('Hello World', 'test.mp3')
engine.runAndWait()
大家好,我在多语言社交网络上工作,我想添加一个选项来收听 post 作为音频我尝试使用 python 进行 gtts,我只是想问一下是否有是一种自动检测语言的方法。 我打算在 python 中使用一个名为 googletrans 的模块来检测 post 的语言,然后在不翻译的情况下阅读它,但我觉得这不是最好的解决方案。 如果您提供任何帮助,我将不胜感激:)
您可以使用 textblob
检测语言:pip install textblob
from textblob import TextBlob
b = TextBlob("bonjour")
text = b.detect_language()
然后用pyttsx3
大声朗读:
pip install pyttsx3
import pyttsx3
engine = pyttsx3.init() # object creation
rate = engine.getProperty('rate') # getting details of current speaking rate
print (rate) #printing current voice rate
engine.setProperty('rate', 125) # setting up new voice rate
voices = engine.getProperty('voices') #getting details of current voice
#engine.setProperty('voice', voices[0].id) #changing index, changes voices. o for male
engine.setProperty('voice', voices[1].id) #changing index, changes voices. 1 for female
engine.say(text)
engine.save_to_file('Hello World', 'test.mp3')
engine.runAndWait()