  Context: Stochastic acceleration is thought to be a key mechanism in the
energization of solar flare electrons.
  Aims: We study whether stochastic acceleration can reproduce the observed
soft-hard-soft evolution of the spectral features of the hard X-ray emitted by
suprathermal electron. We pay special attention to the effects of particle
trapping and escape.
  Methods: The Fokker-Planck equation for the electron distribution is
integrated numerically using the coefficients derived by Miller et al. for
transit-time damping acceleration. The electron spectra are then converted to
photon spectra for comparison with RHESSI observation of looptop sources.
  Results: The presence of particle escape softens the model spectra computed
in the stochastic acceleration framework. The ratio between the efficiency of
trapping and acceleration controls the spectral evolution which follows a
soft-hard-soft pattern. Furthermore, a pivot point (that is, a common crossing
point of the accelerated particle spectra at different times) is found at
around 10 keV. It can be brought into agreement with the observed value of 20
keV by enhanced trapping through an electric potential.
  Conclusions: The model proposed here accounts for the key features observed
in the spectral evolution of hard X-ray emission from looptop sources.
