If the intent is to express the acquisition of a new skill or the starting phases of learning, "learn to + infinitive" is usually more appropriate.
To express what you're learning (a skill, a subject, a language, etc.), we normally use "learn to + infinitive".
Thomas needs to learn to speak Spanish before his trip to Madrid.
Thomas needs to learn speaking Spanish before his trip to Madrid.
You can use the gerund to emphasize the process or how someone learns.
You learn doing things, not just studying them.
We also use the gerund to mention experiential learning, where the focus is on the practice and experience of the activity itself rather than the end goal. For example, this sentence indicates that hands-on experience is a valuable or primary method of learning:
Children often learn doing tasks by imitating adults.
If the intent is to express the acquisition of a new skill or the starting phases of learning, "learn to + infinitive" is usually more appropriate.
Follow the same strategy with other verbs, such as cook, play, write, etc.
Jessica hopes to learn to cook Spanish dishes.
Nancy is trying to learn to write in cursive.