Detect encoding and convert