ndarilek / tts-rs

115 stars 25 forks source link

Crash on macOS- InvalidSubtag for voice language #39

Closed leecbaker closed 1 year ago

leecbaker commented 2 years ago

There's a default voice on macOS Ventura that causes a crash because its language description has an unsupported subtag. The voice is Fiona, with a language of en-GB-u-sd-gbsct. This is may be an upstream problem in unic_langid, but I have not confirmed that.

Observed behaviour:

thread 'main' panicked at 'called Result::unwrap() on an Err value: ParserError(InvalidSubtag)', src/backends/av_foundation.rs:315:72

How to reproduce:

cargo run --example hello_world

My system:

mac OS 13.0.1 (22A400) rustc 1.65.0 (897e37553 2022-11-02)

Temporary workaround

The unwrap() that crashes can be replaced with this as a temporary workaround to avoid the crash:

let language = LanguageIdentifier::from_str(&language).unwrap_or_default();
ndarilek commented 2 years ago

Thanks for the report. Going to look into this next week.

If you'd like to help in the meantime, I did a bit of research and it looks like unic_langid uses unicode language identifiers while macOS generates BCP 47 codes. I guess these are mostly compatible, emphasis on mostly. We have 3 paths:

I'll plan on digging into this more next Monday or Tuesday, but any preliminary research/PRs would be welcome. I found a few potential BCP 47 parsers on crates.rs but didn't do more than search and glance at the results.

Thanks a bunch.

ndarilek commented 2 years ago

Hmm, maybe this crate, or the one it links to? https://lib.rs/crates/oxilangtag

ndarilek commented 2 years ago

Actually, just pushed a refactor to use oxilangtag to the oxilangtag branch. All backends except for the macos backends have been ported.

I need to update my mac to macOS 13 and kind of don't want to deal with that this week. If you can port both mac backends to oxilangtag, confirm that examples now work, and submit a PR on that branch, I can push 0.25.0 and hopefully get this fixed. Otherwise I'll do the upgrade on Monday and finish the port then.

Thanks.