Catalysis of the joining of an amino acid and a nucleic acid (usually tRNA) or poly(ribitol phosphate), with the concomitant hydrolysis of the diphosphate bond in ATP or a similar triphosphate. The reaction forms an aminoacyl-tRNA or a related compound.