The sonic data provide significant rock properties that are commonly used for designing the operational programs for drilling, rock fracturing, and development operations. The conventional methods for acquiring the rock sonic data in terms of compressional and shear slowness (ΔTc and ΔTs) are considered costly and time-consuming operations. The target of this paper is to propose machine learning models for predicting the sonic logs from the drilling data in real-time. Decision tree (DT) and random forest (RF) were employed as train-based algorithms for building the sonic prediction models for drilling complex lithology rocks that have limestone, sandstone, shale, and carbonate formations. The input data for the models include the surface drilling parameters to predict the shear and compressional slowness. The study employed data set of 2888 data points for building and testing the model, while another collected 2863 data set was utilized for further validation of the sonic models. Sensitivity investigations were performed for DT and RF models to confirm optimal accuracy. The correlation of coefficient (R) and average absolute percentage error (AAPE) were used to check the models’ accuracy between the actual values and models’ outputs, in addition to the sonic log profiles. The results indicated that the developed sonic models have a high capability for the sonic prediction from the drilling data as the DT model recorded R higher than 0.967 and AAPE less than 2.76% for ΔTc and ΔTs models, while RF showed R higher than 0.991 with AAPE less than 1.07%. The further validation process for the developed models indicated the great results for the sonic prediction and the RF model outperformed DT models as RF showed R higher than 0.986 with AAPE less than 1.12% while DT prediction recorded R greater than 0.93 with AAPE less than 1.95%. The sonic prediction through the developed models will save the cost and time for acquiring the sonic data through the conventional methods and will provide real-time estimation from the drilling parameters.