• A transformer and convolution-based generative adversarial network (TCGAN) is proposed for ECG generation. • Our TCGAN can generate ECG heartbeats with the waveforms being close to their real counterparts. • The proposed TCGAN model is utilized to alleviate the data-imbalance problem. • The overall accuracy of the proposed method is 94.69% in classifying heartbeats with type N, S, V, and F. Arrhythmia is an important group of cardiovascular diseases, which can suddenly attack and cause sudden death, or continue to affect the heart and cause its failure. Electrocardiogram (ECG) is an important tool for detecting arrhythmia, but its analysis is time-consuming and dependent on extensive expertise. Deep neural networks have become a popular technique for automatically tracing ECG signals, and demonstrate great potentials to be more competent than human experts. However, most life-threatening arrhythmias are extremely rare, limiting the amount of examples available to train deep learning models. To address such a data imbalance problem, this study proposed a novel data augmentation protocol, i.e., a transformer and convolution-based generative adversarial network (TCGAN). Transformer is a recently proposed deep neural network based on the self-attention mechanism, which has powerful capabilities in learning the relationships between sequence elements. The proposed TCGAN is utilized to generate heartbeat signals per type, which are then added to the original dataset to alleviate the data-imbalance problem. Experimental results on the MIT-BIH arrhythmia database demonstrate that our TCGAN can generate ECG heartbeats with the waveforms being close to their real counterparts. In the inter-patient heartbeat classification paradigm, the overall accuracy of the proposed method is 94.69% in classifying heartbeats with type N, S, V, and F. Furthermore, the comparison with several state-of-the-art heartbeat classification systems demonstrates the effectiveness of the proposed TCGAN in enhancing the ECG dataset.