2016-10-02 33 views
0

オーディオファイルに書き込むときにエラーが発生します。Errno 13許可が拒否されました: 'file.mp3' Python

基本的には、私の関数が呼び出されてから再生されるたびにmp3のデータを上書きしています。

これは最初に機能しますが、次に[Errno 13] Permission denied: 'file.mp3'が表示されます。ここで

はコードです:

def speech(self, response): 
    audio_file = "response.mp3" 
    tts = gTTS(text=str(response), lang="en") 
    tts.save(audio_file) 
    pygame.mixer.init() 
    pygame.mixer.music.load(audio_file) 
    pygame.mixer.music.play() 

エラーがtts.saveライン上にあります。

さらに詳しい情報:

Traceback (most recent call last): 

    File "myprojectpath", line 63, in speech 
    tts.save(audio_file) 

    File "C:\Python35\lib\site-packages\gtts\tts.py", line 93, in save 
    with open(savefile, 'wb') as f: 

ありがとう!

+1

を着陸する確率を計算するだろう、これです。 – furas

+0

それをテストする方法はありますか? – Jaromando

+0

pythonスクリプトを管理者として起動しますか? Windowsユーザーは、このファイルにアクセスしますか? ここでは、ファイルまたはフォルダにアクセスしたプロセスを確認する方法を示します。http://superuser.com/questions/117902/find-out-which-process-is-locking-a-file-or-folder-in-windows 前にスクリプトでこのファイルを開きますか? –

答えて

1
from gtts import gTTS 
import playsound 
import os 

x = ['sunny', 'sagar', 'akhil'] 
tts = 'tts' 
for i in range(0,3): 
    tts = gTTS(text= x[i], lang = 'en') 
    file1 = str("hello" + str(i) + ".mp3") 
    tts.save(file1) 
    playsound.playsound(file1,True) 
    print 'after' 
    os.remove(file1) 

保存するたびにファイル名を変更してください。

0

より良い解決策は、私は時間があれば私も多分(それを果たしている)プログラムのブロックは、ファイルへのアクセスをこれまでと同じファイル

from gtts import gTTS 
from playsound import playsound 
import random 
import os 

#creating a super random named file 

r1 = random.randint(1,10000000) 
r2 = random.randint(1,10000000) 

randfile = str(r2)+"randomtext"+str(r1) +".mp3" 

tts = gTTS(text='hey, STOP It!!', lang='en', slow=True) 
tts.save(randfile) 
playsound(randfile) 

print(randfile) 
os.remove(randfile) 
関連する問題