首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pyttsx无法将文本转换为apeech

Pyttsx无法将文本转换为apeech
EN

Stack Overflow用户
提问于 2017-09-09 19:14:44
回答 1查看 125关注 0票数 0

我有下面这段代码。它使用pyttsx进行文本到语音的转换。

代码语言:javascript
复制
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()

它会播放说“无”的声音。响应文本打印在控制台上,但语音模块只说'None‘。为甚麽呢?我也尝试过下面的代码:

代码语言:javascript
复制
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.')时,它会说出并读出短语,同时打印响应文本。

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2017-09-09 19:25:44

您没有向我们展示您的response()函数,但它显然返回了None

这就是导致你所描述的行为的原因。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46130060

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档