You see, the nature of the punishment is irrelevant. Just go ahead and take a look at the First Amendment itself.
Congress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech, or of the press; or the right of the people peaceably to assemble, and to petition the Government for a redress of grievances.
And then later on we added the Fourteenth Amendment.
Section 1. All persons born or naturalized in the United States, and subject to the jurisdiction thereof, are citizens of the United States and of the State wherein they reside. No State shall make or enforce any law which shall abridge the privileges or immunities of citizens of the United States; nor shall any State deprive any person of life, liberty, or property, without due process of law; nor deny to any person within its jurisdiction the equal protection of the laws.
Ever since 1925 with Gitlow v. New York, the Supreme Court has sustained the precedent that the specific portion that I highlighted above works to apply the protections guaranteed in the Bill of Rights to the states as well as the federal government, in what is termed the incorporation doctrine.
Now, for the legislation itself, the "obscenity" argument will invariably come up- indeed, it's only one of two general rationals for barring speech currently allowed by the Court, with the other relating to that which is "directed to inciting or producing imminent lawless action and is likely to incite or produce such action". (I pretty much disagree with the obscenity rational in the first place, but that's a discussion for another day.) But what exactly is obscenity in a legal sense? Thankfully, the Court has our backs here as well with the Miller Test, the current standard that must be used to make such a determination.
It goes like so:
1. Would "the average person, applying contemporary community standards" find that the work (i.e. piece of speech/expression), taken as a whole, appeals to the prurient interest?
2. Does the work depict or describe, in a patently offensive way, sexual conduct or excretory functions specifically defined by applicable state law?
3. Does the work, taken as a whole, lack serious literary, artistic, political, or scientific value?
Only if all three of these questions can be definitively answered in the affirmative will speech be declared obscene and thus outside the bounds of First Amendment protection.
It is self-evident that such "anti-public swearing" legislation does not take any of this into account- it can't, because it works indiscriminately rather than on a case-by-case basis. Thus, it is completely and totally unconstitutional.