In a German sentence, the conjugated verb always appears at the 2nd position. In your example, it is "fing an". Now, if we have another verb that depends on this main verb, such as an infinitive with "zu", it goes at the very end of the sentence, as "zu lernen" in your example.
In the same way, every subordinate clause in German has the verb at the end.
Your second example, "Ich spreche Deutsch" has only one verb, so it naturally comes at the 2nd position in the sentence.