To better understand the function of optical gas sensor at high temperature (~1000 K), we use density functional theory to study the temperature dependence of the energy gaps in the sensor materials, including TiO2 and SrTiO3, due to the electron-phonon interaction and thermal expansion. The electron-phonon interaction is simulated using both Allen-Heine-Cardona (AHC) theory and finite displacement method, while thermal expansion study is based on the quasiharmonic approximation. Our simulation agrees with experiments. Our calculation also reveal that the thermal expansion contribution is as important as electron-phonon interaction in TiO2.