You are correct in your assumption. The usage does depend on the pronunciation. If the subsequent word has a **vowel** sound, then the previous word must be **an**. If the word has a **consonant** sound, then the previous word is **a**.