If the prolem lies only in the AVI video-audio connection, you could try to extract the whole audio stream (e.g. with VirtualDub, with Audio set on Full Processing Mode then doing File___Save WAV) and to load separately the AVI as 'video input' and the WAV file with 'audio input' with TMPGenc.
This will work if the WAV's length matches the AVI's one.
If you cannnot save the whole stream, you're in trouble....
This is only a guess, take care...my point of view is that if the input is garbage, it's very likely you cannot correct it.