In a dictionary, the pronunciation guide for the word "X-ray" is: eks ˌrā
Notice what the first letter of the pronunciation is e, which is a vowel, thus a vowel sound is the first sound produced when anyone pronounces the word X-ray correctly.
The letter x can begin with either a vowel sound or a consonant sound depending on the word. In certain words that begin with x, the initial sound of the x is actually a z sound:
xylophone is: zīləˌfōn Therefore, a xylophone would be correct.
Use the a if the x is pronounced as a consonant; use an if the x is pronounced as a vowel.