Optical spectrometers are essential tools for analysing light‒matter interactions, but conventional spectrometers can be complicated and bulky. Recently, efforts have been made to develop miniaturized spectrometers. However, it is challenging to overcome the trade-off between miniaturizing size and retaining performance. Here, we present a complementary metal oxide semiconductor image sensor-based miniature computational spectrometer using a plasmonic nanoparticles-in-cavity microfilter array. Size-controlled silver nanoparticles are directly printed into cavity-length-varying Fabry‒Pérot microcavities, which leverage strong coupling between the localized surface plasmon resonance of the silver nanoparticles and the Fabry‒Pérot microcavity to regulate the transmission spectra and realize large-scale arrayed spectrum-disparate microfilters. Supported by a machine learning-based training process, the miniature computational spectrometer uses artificial intelligence and was demonstrated to measure visible-light spectra at subnanometre resolution. The high scalability of the technological approaches shown here may facilitate the development of high-performance miniature optical spectrometers for extensive applications.