'hardly' means 'only with great difficulty'
'barely' means 'only just'
Which word you use depends on whether you want to emphasize 'you were only just able to do something' or, 'were able to do it some degree, but boy, it took some effort'
"He was talking so fast, I could barely understand a word he said."
I am emphasizing that I only just understood what he was saying.
He: Did you explain to Paul?
She: "He was talking so much, I could barely/hardly get a word in edgeways."
With 'barely', she is intimating that she had little luck in having a conversation with him, he was talking 'at her'. (She may go on to say that of what she did say, she is unsure how much he really 'heard' and took in , and suggest they try again when Paul has calmed down.)
With 'hardly', she is intimating that it was tough going, but she really tried...(and will then probably go on to say how Paul responded to the 'explaining' she did.)
Do you want to stress the sense that you were almost overwhelmed by the task/situation; or how much effort you had to put into it to try to achieve it to the small degree that you were able.
barely: seems to convey a positive sense - you just manage to do something.
hardly: seems to convey a negative sense - you can't manage to do something.
But we do come across these words and 'scarcely' used in the same sense. It may well be a matter of style rather than strict meaning that would determine which word is to be used.