There is a difference for some things. To try TO DO something is the same as to attempt DOING something, but there are other ways in which it doesn't work:
Correct: I tried to build a house of cards, but it fell over. <-- sounds most natural
Correct: I attempted building a house of cards, but it fell over. <-- sounds a bit weird/formal, but it is still OK.
Correct: I tried some of the apple pie, but it tasted horrible!
Incorrect: I attempted some of the apple pie. <-- They are not synonyms when it comes to 'to try' as a verb for tasting things.
Correct: I attempted a recipe I saw in a book. <-- Here, even though we're using a noun, an action is implied, You're trying to COOK a recipe or to MAKE a recipe.
Correct: I tried (out) a recipe I saw in a book.
In the examples above, the last one sounds most natural for 'attempt' because the *feeling* of 'to attempt' is that the task/project/outcome you're trying to achieve is particularly difficult or the chances of success are a bit lower. It also sounds most natural to use 'attempt' with a noun, even though you can technically use it with a verb.
Short version: If you're not sure, use "to try"!