Serial-ATA / lofty-rs

Audio metadata library
Apache License 2.0
176 stars 34 forks source link

Wav: Failed to read RIFF INFO item value #373

Open Ferry-200 opened 2 months ago

Ferry-200 commented 2 months ago

Reproducer

I tried this code:

let tagged_file: Option<TaggedFile> = match lofty::read_from_path(
        "C:\\Users\\ferry\\Music\\test\\大哉乾元(洛天依人声版)_MMM.wav",
    ) {
        Ok(value) => Some(value),
        Err(err) => {
            // Wav: Failed to read RIFF INFO item value
            println!("{}", err);
            None
        }
    };

The lofty version is "0.18.2" image

Summary

There is an error "Wav: Failed to read RIFF INFO item value"

The Windows Properties page can read the tags in it. I can also play it on Windows Media Player.

Can anyone provide some information about this? Thanks.

Expected behavior

Read tag correctly.

Assets

大哉乾元(洛天依人声版)_MMM.wav

Serial-ATA commented 2 months ago

Hello!

Your file has items that are not UTF-8 encoded. What is your local character encoding? If Windows is able to read it, that means the file is using your system encoding.

Ferry-200 commented 2 months ago

UTF-16. And the file's tags are UTF-16 LE encoded.

Serial-ATA commented 2 months ago

Hm. It's unfortunate that RIFF doesn't specify a text encoding. We would be able to somewhat reliably detect UTF-16 LE, but there's no BOM either. The only way for us to know ahead of time how to decode the text would be using GetACP() from Windows. Don't know how I feel about having platform-specific code in Lofty, though.

Ferry-200 commented 2 months ago

Maybe we can simply set the way to decode text when reading riff info. Obviously it is not a good way to fix it though.

And this is the way how the Taglib support it. StringHandler

StringHandler

Detailed Description

An abstraction for the string to data encoding in Info tags.

RIFF INFO tag has no clear definitions about character encodings. In practice, local encoding of each system is largely used and UTF-8 is popular too.

Here is an option to read and write tags in your preferred encoding by subclassing this class, reimplementing parse() and render() and setting your reimplementation as the default with Info::Tag::setStringHandler().

Serial-ATA commented 2 months ago

That would also work. Gonna have to think about this one. For now I'd just recommend changing the encoding of your files to UTF-8, that's what most libraries (outside of TagLib) will exclusively support.