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)
응답 해 주셔서 감사합니다. 이제이 기능을 추가했습니다. Return "+ 응답 (문장)을 추가하려고했습니다. 그것은 작동하지 않았다. 나는 그것이 틀렸다는 것을 나는 가정했다. 엔진이 무엇을 반환해야하는지, 엔진에 무엇을 넣어야 하는지를 알 수 있도록 도와 주시겠습니까? –
감사합니다. 나는 해결했다. –