Detect encoding when unicode conversion fails.