Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The playsound library encountered an issue when attempting to use the temporary file path in Windows, resulting in an error during playback. #147

Open
marvinbraga opened this issue Oct 4, 2023 · 0 comments

Comments

@marvinbraga
Copy link

Issue Description

Problem

The playsound library encountered an issue when attempting to use the temporary file path in Windows, resulting in an error during playback.

  File "C:\Users\user_name\AppData\Local\pypoetry\Cache\virtualenvs\llms-course-cecv-ynhqYloT-py3.10\lib\site-packages\playsound.py", line 72, in _playsoundWin
    winCommand(u'open {}'.format(sound))
  File "C:\Users\user_name\AppData\Local\pypoetry\Cache\virtualenvs\llms-course-cecv-ynhqYloT-py3.10\lib\site-packages\playsound.py", line 64, in winCommand
    raise PlaysoundException(exceptionMessage)
playsound.PlaysoundException: 
    Error 305 for command:
        open "C:\Users\user_name\AppData\Local\Temp\PSelb4boc8.mp3"

Solution

An adjustment was made to the _playsoundWin function to correctly utilize the temporary file path. The modification involved using os.path.normpath to ensure the correct formatting of the temporary file path in Windows.

Code Modification

# Existing code
    def winCommand(*command):
        bufLen = 600
        buf = c_buffer(bufLen)
        command = ' '.join(command).encode('utf-16')
        errorCode = int(windll.winmm.mciSendStringW(command, buf, bufLen - 1, 0))  # use widestring version of the function
        if errorCode:
            errorBuffer = c_buffer(bufLen)
            windll.winmm.mciGetErrorStringW(errorCode, errorBuffer, bufLen - 1)  # use widestring version of the function
            exceptionMessage = ('\n    Error ' + str(errorCode) + ' for command:'
                                '\n        ' + command.decode('utf-16') +
                                '\n    ' + errorBuffer.raw.decode('utf-16').rstrip('\0'))
            logger.error(exceptionMessage)
            raise PlaysoundException(exceptionMessage)
        return buf.value

    if '\\' in sound:
        sound = '"' + sound + '"'

    # Modified code (added line to normalize the temporary file path)
    sound = os.path.normpath(sound)

This modification ensures that the temporary file path is correctly formatted for Windows, allowing playsound to utilize the temporary file without encountering errors.

Steps to Reproduce

  1. Use the playsound library on Windows.
  2. Attempt to play an audio file using a temporary file path.
  3. Observe the error encountered due to incorrect formatting of the temporary file path.

Expected Behavior

The playsound library should be able to utilize the temporary file path correctly on Windows and play the audio file without errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant