In this paper, we explore the effect of musical context on audio onset detection using machine learning techniques. We extract the signal intensity and frequency energy of audio as the attributes of input instances for the machine learning techniques. The audio is synthesized from MIDI files, providing exact information of onset events. We test three state-of-the-art machine learning algorithms, Support Vector Machines (SVM), Neural Networks (NN), and Naïve Bayes (NB) with Ada boosting, for learning and classifying audio onsets. We found that SVMs perform best in general, based on the average of training and 10-fold cross validation errors as the evaluation criterion. We then test the SVM and NN, the two best performing methods, on Bach's Prelude in C major BWV 943, transposed to different keys and time-stretched to various tempi. The error rates ranged from 23.91% (when training set key and tempo equals those of the test set) to 37.22% (when the key is off by four accidentals) and 37.91% (when tempo is 20 beats per minute faster). The results show that audio onset detection performs significantly better when the key and tempo attributes of the test and training sets concur, than when they are different, thus supporting the utility of tempo and key knowledge in designing onset detection systems, or in prescribing confidence statistics to onset detection outcomes.