This was how the birth of Jesus Christ took place. His mother Mary was engaged** to Joseph, but before they were married, she found out that she was going to have a baby by the Holy Spirit. Joseph was a man who always did what was right, but he did not want to disgrace Mary publicly; so he made plans to break the engagement** privately.
Matthew suggests that the experience was "inside his head", but still very real.
While he was thinking about this, an angel of the Lord appeared to him in a dream and said, “Joseph, descendant of David, do not be afraid to take Mary to be your wife. For it is by the Holy Spirit that she has conceived. She will have a son, and you will name him Jesus - because he will save his people from their sins.”
Jesus was a common-as-mud name, the equivalent of our Joshua. In Hebrew the name means "God saves".
But Joseph had no sexual relations with her before she gave birth to her son. And he named him Jesus.
In many traditions it is called the Magnificat.
Mary was praising God in the only way she knew - by reciting a memorable passage from her "bible", our Old Testament book of Samuel.
** Engaged/Engagement is not a good translation. "Betrothed", in the Jewish culture of the day, was more like a "trial marriage". Being pregnant before the due ceremony would normally mean that the woman would be literally thrown out.