Chapter 111 of 133
الدُّعَاءُ عِنْدَ صِيَاحِ الدِّيكِ وَنَهِيقِ الحِمَارِ
إِذَا سَمِعْتُمْ صِيَاحَ الدِّيَكَةِ فَاسْأَلُوا اللَّهَ مِنْ فَضْلِهِ، فَإِنَّهَا رَأَتْ مَلَكًا. وَإِذَا سَمِعْتُمْ نَهِيقَ الحِمَارَ فَتَعَوَّذُوا بِاللَّهِ مِنَ الشَّيْطَانِ، فَإِنَّهُ رَأَى شَيْطَانًا
Translation
If you hear the crow of a rooster, ask Allah for his bounty for it has seen an angel and if you hear the braying of an ass, seek refuge in Allah for it has seen a devil.
Reference
البخاري مع الفتح 6/ 350 ومسلم 4/ 2092
References are as given in Hisn al-Muslim (book volume/page).
Source: Hisn al-Muslim by Sa'id ibn Ali ibn Wahf al-Qahtani. Arabic text and references: asellam/HisnElMuslim. English translation, transliteration and audio: hisnmuslim.com.