I only realized it was him when I heard him speak.
Literal
Speaking [nominalizer-の] [object-を] heard [and-て] first-time he [copula-だ] [quotative-と] understood.
~て初めて ('only after doing') creates a temporal-causal chain: the recognition happened only upon hearing the voice. の nominalizes 話す so it can take を. The quotative と after 彼だ marks the content of the realization.