Sonos Inc. posted a surprise profit Wednesday afternoon as the maker of smart speakers continued to see strong demand for its products.