0
私は次のコードを書いています。どのpyttsxを使用して音声変換をテキストにしますか?Pyttsxはテキストを音声に変換できません
sys.stdout.write("> ")
#sys.stdout.flush()
classify(sentence = sys.stdin.readline())
while True:
sentence = sys.stdin.readline() #input sentence
text = response(sentence) #response to the input sentence.
engine = pyttsx3.init()
rate = engine.getProperty('rate')
engine.setProperty('rate', rate - 5)
engine.say(text) #converts the text to speech
engine.runAndWait()
「なし」という音が鳴ります。応答テキストはコンソールに表示されますが、スピーチモジュールは「なし」以外は何も話しません。なぜそうですか?私も以下のコードを試しました:
sys.stdout.write("> ")
#sys.stdout.flush()
classify(sentence = sys.stdin.readline())
while True:
sentence = sys.stdin.readline() #input sentence
response(sentence) #response to the input sentence.
engine = pyttsx3.init()
rate = engine.getProperty('rate')
engine.setProperty('rate', rate - 5)
engine.say(response(sentence)) #converts the text to speech
engine.runAndWait()
しかし、それはどちらかと思われません。引数をengine.say()
文字列に渡している間に私は間違いを犯していますか? engine.say('I'm working.')
と書くと、レスポンステキストを印刷している間に、そのフレーズを読み上げて読み上げます。
def response(sentence, userID='123', show_details=False):
# if we have a classification then find the matching intent tag
if results:
# loop as long as there are matches to process
while results:
for i in intents['intents']:
# find a tag matching the first result
if i['tag'] == results[0][0]:
# set context for this intent if necessary
if 'context_set' in i:
if show_details: print ('context:', i['context_set'])
context[userID] = i['context_set']
# check if this intent is contextual and applies to this user's conversation
if not 'context_filter' in i or \
(userID in context and 'context_filter' in i and i['context_filter'] == context[userID]):
if show_details: print ('tag:', i['tag'])
# a random response from the intent
return print(random.choice(i['responses']))
results.pop(0)
ご回答ありがとうございました 私は今機能を追加しました。私は返信 "+応答(文)を追加しようとしました。それはうまくいかなかった。私はそれが間違っていたと思います。あなたは何を返すべきか、何をエンジンに入れなければならないのか理解してもらえますか?それは私のために話すのですか? –
ありがとうございます。私はそれを解決した。 –