Chosen Solution

suddenly my iPhone earpiece is not working some times its automatically working and not working some time

Sounds like a faulty ear piece speaker or front camera flex cable which has the connection to the speaker.