In a sense, Scripture preserves for us the voice of God.
God, after He spoke long ago to the fathers in the prophets in many
portions and in many ways, 2 in these last days has spoken to us in
His Son – Heb 1:1-2 (NASB)
That the story of the sheep and the shepherd is a parable indicates that the individual elements are not meant to be taken literally. Rather, the analogy of the sheep and the shepherd calls attention to the relationship between the two. The role of the shepherd is to care for and protect his sheep. Psalm 23 offers a glimpse of what this looks like from a spiritual perspective.
The Lord is my shepherd; I shall not want. He maketh me to lie down
in green pastures: he leadeth me beside the still waters. He
restoreth my soul: he leadeth me in the paths of righteousness for his
name's sake. – Psalm 23:1-3 (KJV)
Though the sheep can hear other voices, they recognize the voice of the shepherd and can distinguish it from all the others. Likewise, the shepherd knows the sheep. Theirs is a relationship based on mutual knowing. That the sheep can hear the voice of the shepherd is a reflection of their familiarity and trust in the shepherd. This hearing of the shepherd’s voice can therefore serve as an analogy for faith.
In the passage of John 5, the interplay between hearing and believing goes beyond the parable and factors into the discourse between Jesus and his opponents. While they can physically hear Jesus, they are said to be unable to hear his voice or, in other words, they do not believe him.
v 25-27 (KJV) – Jesus answered them, I told you, and ye believed not:
the works that I do in my Father's name, they bear witness of me. 26
But ye believe not, because ye are not of my sheep, as I said unto
you. 27 My sheep hear my voice, and I know them, and they follow me
“But ye believe not, because ye are not of my sheep.” Being “of My sheep” is shown to be the key to believing in the shepherd. To further understand what Jesus means by being “of my sheep,” it helps to examine a similar discourse in John 8.
43 Why do you not understand what I am saying? It is because you
cannot listen to My word. 44 You are of your father the devil, and you
want to do the desires of your father… If I speak truth, why do you
not believe Me? 47 The one who is of God hears the words of God; for
this reason you do not hear them, because you are not of God. – Jn
8:43-47 (NASB)
“My word” and the “words of God” correspond to “my voice,” and being “of God” corresponds to being “of my sheep.” In John 10, those who cannot hear Jesus’ voice are those who are not of his sheep. In John 8, those who cannot hear his word and God’s words are those who are “not of God.” From the context “not of God” means they follow a will that is in direct opposition to God’s will (Jn 8:44).
Returning to the OP’s question, hearing the shepherd’s voice is a complex process that goes beyond physical (or perhaps even mystical) hearing. It is closely linked to faith and is rooted in how each person aligns himself with regard to the will of God. The notion of hearing yet not hearing is an important theme of the text and echoes of it can be found throughout Scripture (cf Ps 135:17, Is 42:20, Jer 5:21, Ez 12:2, Is 6:10, Acts 28:24-28).
This is why I speak to them in parables: “Though seeing, they do not
see; though hearing, they do not hear or understand. 14 In them is
fulfilled the prophecy of Isaiah."
– Matthew 13:13-14