In musical terms this is called audiation - the ability to imagine sound. From my experience, this can be acquired indirectly over time through regular vocal and musical practice (e.g., singing in a local choir or practicing an instrument). You can write music with or without it, or using both: sometimes you have a specific sound in your head that you want to materialize, other times you're experimenting with your instrument and discovering new sounds that you could not have imagined.
I don't know how much of this applies to visual artists, but there's probably some overlap there.