如何重复使用gtts?

时间:2019-04-07 19:46:10

标签: python gtts

当我一次调用我的函数时,我没有任何错误,但是如果我反复地调用它,我将出现以下错误:

  

发生异常:PermissionError [Errno 13]权限被拒绝:   'tolkback.mp3'

SQL> DECLARE
  2    firstname   VARCHAR(50):= 'Rob';
  3    budget      NUMBER := 600;       -- missing colon
  4    counter     NUMBER;
  5  cursor all_products is
  6    SELECT product_name,
  7           list_price
  8    FROM product_information;        -- I removed OE. (as I don't have that schema)
  9
 10  BEGIN
 11    counter := 0;
 12    FOR items IN all_products LOOP
 13      IF(items.list_price <= budget)THEN
 14        counter := counter + 1;
 15      END IF;
 16    END LOOP;
 17
 18    dbms_output.put_line(firstname
 19                         || ', you can afford '
 20                         || TO_CHAR(counter)
 21                         || ' items.');
 22  END;
 23  /
Rob, you can afford 1 items.

PL/SQL procedure successfully completed.

SQL>

程序应回复文字

1 个答案:

答案 0 :(得分:1)

这是我和我的朋友furas的助手所完成的解决方案

from playsound import playsound
import webSearch
import os
import random

def name_generator():
    ran = random.randint(1,5000)
    ran = str(ran)
    return ran


def TalkBack(case_ans):
    print("in ...................................")
    tts = gTTS(case_ans)
    new_name = name_generator()
    new_name= new_name+".mp3"
    tts.save(new_name)

    print("saving...............................")
    playsound(new_name)
    print("saying................................")
    try:
        os.remove(new_name) 
    except:
        print("i cant")



TalkBack("my bad end 1")
TalkBack("go go end 2")
TalkBack("find me my self end 3")
TalkBack("games maker end 4")
TalkBack("say my name end 5")

使用随机名称生成一个新的.mp3文件,并在使用后将其删除