My microphone and headphone is connected to a Behringer U-Phoria UM2 which is also connected to my PC. I love singing along with a karaoke file playing in my PC. While singing, I can hear my voice and the playing karaoke track in my headphones but Audacity only records my voice. How can we record the voice/microphone and the audio file playing in the PC at the same time?
You need to do “overdub” recording. There’s a tutorial in the manual: https://manual.audacityteam.org/man/tutorial_multi_track_overdubbing.html
What’s supposed to happen is you play the backing track (karaoke track) in Audacity. It’s basic overdubbing setup. Don’t play the music in your computer music player.
Audacity produces a sister track to the backing track with just your voice on it. After the performance, you play both and independently adjust the mix and quality of the backing track and your voice. When you export, Audacity will mix the two together into a finished song.
If you insist on mixing in real time, you’re stuck with the mix. There is no way to apply corrections, filtering, effects or timing to just one track. Any mistake is immediately fatal.
If all you want to do is sing and export a mix, do just that. You don’t have to apply changes to either one.