There are a lot of ways you can develop a good ear for music, some of which require a lot of work and patience. One of the more enjoyable ways of developing a good ear is singing what you’re playing. Whether you’re improvising or just playing a melody that is written down, sing along with the music. This is a good way to become familiar with scales, intervals and other aspects of music. With enough practice, you’ll be able to improvise and sing exactly what you’re playing.
For an example of someone who sang and played at the same time, check out George Benson, a famous jazz guitarist. In fact, if you listen to jazz enough you’ll hear a lot of guitarists and pianists who sing what they’re playing.