2017-06-21 64 views
0

我試圖讓一個文本到語音的GUI程序,這裏是我得到的錯誤,說明文件已經被另一個程序TTSpygame.mixer.quit()不工作

b = a.get() 

blabla = b 
tts = gTTS(text=blabla, lang='en-us') 
try : 
    tts.save("F:/tesst.mp3") 
except : 
    pass 
pygame.init() 
pygame.display.set_mode((2, 1)) 
try: 
    pygame.mixer.music.load("F:/tesst.mp3") 
except : 
    pass 
mixer.music.play(0) 

clock = pygame.time.Clock() 
clock.tick(10) 
while pygame.mixer.music.get_busy(): 
    pygame.event.poll() 
    clock.tick(10) 
mixer.music.set_endevent() 
mixer.quit() 
os.remove("F:/tesst.mp3") 

代碼,所以我無法遞歸運行程序。 這裏是錯誤

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'F:/tesst.mp3'

回答

0

看起來你沒有在加載它後發佈文件。與上下文經理試圖傳遞一個文件對象,而不是一個文件來加載方法:

... 

with open('F:/tesst.mp3', 'rb') as file_object: 
    pygame.mixer.music.load(file_object) 

mixer.music.play(0) 

... 

從上下文管理器的資源將被釋放。一旦退出。

+0

不工作,我得到的錯誤爲'in speak pygame.mixer.music.load(file_object) pygame.error:Could not read from RWops' –