'How to play MP3 files with Chinese filename

I'm using python package playsound 1.2.2 to play mp3 files. Everything is OK until I tried to play sound files with Chinese characters. It throw an error

Error 275 for command: open "c:\temp\x1_好的.mp3" alias playsound_0.4552274050349264 Cannot find the specified file. Make sure the path and filename are correct.

Here is my code:

import os
from playsound import playsound


filename = 'c:\\temp\\x1_好的.mp3'
#filename = 'c:\\temp\\x1.mp3'
if os.path.exists(filename):
    print('ok')
    playsound(filename)
else:
    print('file not exists')

How do I deal with this? I'm using python version 3.8.8 on a Windows 7 OS.



Solution 1:[1]

I'm using Mac but got curious about this. Looks like a file name encoding issue.

So, there's a related issue/patch, mainly from

command = ' '.join(command).encode(getfilesystemencoding())

to:

command = ' '.join(command).encode('utf-16')

which is now in the latest version (1.3.0) also. I think you could try upgrading the package version from 1.2.2 (June 2017) to 1.3.0 (July 2021):

pip install playsound==1.3.0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1