Playing a sound depending on the currently displayed flash card image
You shouldn't determine the sound to play from the image displayed.  Instead you should use the same piece of information to set both the image name and the sound path.

Create a property of your ViewController to keep track of the card number that is being displayed:

var displayedCard = 1


and set it whenever you assign a new image to the imageView:

// if the tapped view is a UIImageView then set it to imageview
if (gesture.view as? UIImageView) != nil {
    if segControl.selectedSegmentIndex == 0 &amp;&amp; segControl2.selectedSegmentIndex == 0 {
        imageView.image = UIImage(named: "card\(number)")
        displayedCard = number
        number = number % 26 + 1
    }
    else if segControl.selectedSegmentIndex == 0 &amp;&amp; segControl2.selectedSegmentIndex == 1 {
        imageView.image = UIImage(named: "upper\(number)")
        displayedCard = number
        number = number % 26 + 1
    }


Then use it to create the String you pass to URL(fileWithPath:):

// create the soundPath using displayedCard
let letter = String(UnicodeScalar(96 + displayedCard)!)
let soundPath = Bundle.main.path(forResource: "\(letter)Sound.m4a", ofType:nil)!

do { audioPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: soundPath))
    audioPlayer.play()
} catch {
    print("Couldn't load sound file")
}