~ているとき can express "the event of the main clause continues during the period of the subordinate clause" other than ~ているときに "the event of the main clause happens at a moment in the period of the subordinate clause" like your examples. In this case, it can't be replaced with ~ているあいだに. Instead, ~ているあいだ is used. Thus, the answer is no. They are not always interchangeable.
at a moment in the period
○お風呂に入っているとき、電話が鳴った。
○お風呂に入っているときに、電話が鳴った。
○お風呂に入っているあいだに、電話が鳴った。
×お風呂に入っているあいだ、電話が鳴った。
during the period
○お風呂に入っているとき、ずっと歌を歌っていた。
△お風呂に入っているときに、ずっと歌を歌っていた。*
△お風呂に入っているあいだに、ずっと歌を歌っていた。*
○お風呂に入っているあいだ、ずっと歌を歌っていた。
* These two sentences can be valid, but the meanings are different from just とき or あいだ.