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

python scikits.audiolab Sndfile special chars in file name #26

Open
Fuqran opened this issue Aug 18, 2014 · 2 comments
Open

python scikits.audiolab Sndfile special chars in file name #26

Fuqran opened this issue Aug 18, 2014 · 2 comments

Comments

@Fuqran
Copy link

Fuqran commented Aug 18, 2014

Hi ,
I am trying to get a wav file information but Sndfile is unable to read file with special characters in path and file name(查找問題daw.wav) , i am unable to get information in any way i mentioned in the code , i tried passing file path to Sndfile with diferent encoding to but didnt work , but if i pass this 'C:\Users\Furqan\Desktop\test\DAW\1.wav' it works fine ,
Help me !
Thanks is advance

My Code is

-- coding: UTF-8 --

from scikits.audiolab import Sndfile
from os import walk, path, stat

track1 =  r'C:\Users\Furqan\Desktop\test\查找問題daw\1.wav'
#track1 = r'C:\Users\Furqan\Desktop\test\DAW\1.wav'

try:
    track_one_file_obj = Sndfile(track1, 'r')
except:

    print('Simple didnt work')
    print(Exception.message)
    print('')
    pass

try:
    track_one_file_obj = Sndfile(track1.decode('cp1252'), 'r')
except:
    print('cp1252 didnt work')
    print(Exception.message)
    print('')
    pass

try:
    track_one_file_obj = Sndfile(track1.encode('utf-8'), 'r')
    print(track_one_file_obj)
except:
    print('encode didnt work')
    print(Exception.message)
    print('')
    pass


try:
    track_one_file_obj = Sndfile(track1.encode('utf8'), 'r')
    print(track_one_file_obj)
except:
    print('encode didnt work')
    print(Exception.message)
    print('')
    pass

try:
    track_one_file_obj = Sndfile(track1.decode('utf-8'), 'r')
    print(track_one_file_obj)
except:
    print('decode didnt work')
    print(Exception.message)
    print('')
    pass

try:
    track_one_file_obj = Sndfile(track1.decode('utf8'), 'r')
    print(track_one_file_obj)
except:
    print('decode didnt work')
    print(Exception.message)
    print('')
    pass

print(track_one_file_obj.nframes)
@mgeier
Copy link

mgeier commented Oct 26, 2015

If you don't want to wait for scikits.audiolab to fix this, you can use PySoundFile, which supports those kinds of file names since version 0.8.0.

@vokimon
Copy link

vokimon commented Dec 7, 2015

If such characters are supported by you locale code page, what about:

For Python 3: https://docs.python.org/3/howto/unicode.html

#!/usr/bin/env python3
from scikits.audiolab import Sndfile
track1 =  r'C:\Users\Furqan\Desktop\test\查找問題daw\1.wav'
sndfile = Sndfile(track1.encode(sys.filesystemencoding()), 'r')

For Python 2: https://docs.python.org/2/howto/unicode.html

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from scikits.audiolab import Sndfile
track1 =  ru'C:\Users\Furqan\Desktop\test\查找問題daw\1.wav'
sndfile = Sndfile(track1.encode(sys.filesystemencoding()), 'r')

It should work whenever the locale codepage is able to encode the unicode characters in the filename. But that would be a limitation on what the system is able to do. using the unicode string (or decode it as unicode if it is bytes provided that we know the original encoding) and pass it to the wchar_t function should be the way in windows.

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

3 participants