首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >删除语音助手上的后端mp3文件

删除语音助手上的后端mp3文件
EN

Stack Overflow用户
提问于 2020-12-03 23:08:35
回答 1查看 33关注 0票数 0

我正在使用教程构建一个语音助手。I am attaching the link below for reference

现在,在函数def assistant_speaks(输出)中,我做了一些更改。现在,每当助手说话时,都会生成一个后端mp3文件。这些文件是随机编号的。我想在语音助手停止后删除这些mp3文件。如何做到这一点呢?这是代码-

代码语言:javascript
复制
num = random.randint(1,10000000000)
def assistant_speaks(output):
    global num 
    num += 1
    print("PerSon : ", output) 
    toSpeak = gTTS(text = output, lang ='en', slow = False) 
    file = str(num)+".mp3" 
    toSpeak.save(file) 
    playsound.playsound(file, True)  
    os.remove(file)
EN

回答 1

Stack Overflow用户

发布于 2021-02-13 18:22:26

这对我很有效。我没有使用变量num作为全局变量,而是直接将其传递给函数。

代码语言:javascript
复制
def assistant_speaks(output, num):
    num += 1
    print("PerSon : ", output) 

    toSpeak = gTTS(text = output, lang ='en', slow = False) 
    file = str(num)+".mp3" 
    toSpeak.save(file) 
    playsound.playsound(file, True)  
    os.remove(file)
num = random.randint(1,10000000000)
assistant_speaks("Hello", num)

希望这对你有用。(如果没有,请让我知道)

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

https://stackoverflow.com/questions/65128622

复制
相关文章

相似问题

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