import tempfile
import os
import random
import tkinter as tk
from pydub import AudioSegment
from pydub.playback import play
FFMPEG_PATH = "C:/ffmpeg/bin/ffmpeg.exe"
os.environ["PATH"] += os.pathsep + os.path.dirname(FFMPEG_PATH)
# Load the sound effects
win_sound = AudioSegment.from_file("win_sound.mp3", format="mp3", ffmpeg=FFMPEG_PATH)
lose_sound = AudioSegment.from_file("lose_sound.mp3", format="mp3", ffmpeg=FFMPEG_PATH)
tie_sound = AudioSegment.from_file("tie_sound.mp3", format="mp3", ffmpeg=FFMPEG_PATH)
# create temporary files for the output
with tempfile.NamedTemporaryFile(suffix=".wav") as win_file:
with tempfile.NamedTemporaryFile(suffix=".wav") as lose_file:
with tempfile.NamedTemporaryFile(suffix=".wav") as tie_file:
# export the audio to the temporary files
win_sound.export(win_file.name, format="wav")
lose_sound.export(lose_file.name, format="wav")
tie_sound.export(tie_file.name, format="wav")
# Play sounds
# Play sound effect and animate the result
play(AudioSegment.from_file(win_file.name))
play(AudioSegment.from_file(lose_file.name))
play(AudioSegment.from_file(tie_file.name))
Output
Traceback (most recent call last): File "c:\Users\IK959\code\idk.py", line 22, in win_sound.export(win_file.name, format="wav") File "C:\Users\IK959\code.venv\lib\site-packages\pydub\audio_segment.py", line 867, in export out_f, _ = _fd_or_path_or_tempfile(out_f, 'wb+') PermissionError: [Errno 13] Permission denied: 'C:\Users\IK959\AppData\Local\Temp\tmpmf92cajm.wav'
I tried fixing it by making my own temp files but i cant figure it out