A federal court judge Monday ruled a Massachusetts General Law prohibiting the secret audio recording of police or government officials is unconstitutional.

Chief United States District Judge Patti B. Saris made the ruling on two similar cases -- one involving two Jamaica Plain residents who frequently record police officers and a second case involving Project Veritas, the undercover organization founded by conservative political activist James O'Keefe.

Both cases involved defendants who had not secretly recorded police but claimed that the Suffolk District Attorney's office and the Boston Police Department were interpreting state law in such a way that was preventing them from doing so without the risk of legal repercussions.

Project Veritas argued it was being prevented from conducting the secret video recordings that are the bread and butter of its video reports here in Massachusetts due to the state's interpretation of the law, which would make such recordings illegal.

The defendants in the cases are Suffolk District Attorney Daniel Conley and Boston Police Commissioner William Gross.

In the 44-page decision Saris declared that "secret audio recording of government officials, including law enforcement officials, performing their duties in public is protected by the First Amendment, subject only to reasonable time, place and manner restrictions."

Saris said the cases did not focus on defining what "public space" or "government official" were and the court would "leave it to subsequent cases to define these terms on a better record."

K. Eric Martin and Rene Perez are the two Jamaica Plain defendants in one of the cases. A lawsuit was filed on their behalf by the ACLU of Massachusetts.

According to court records, Martin has openly recorded police officers performing their duties in public at least 26 times and Perez has done the same thing 18 times since 2011. The recordings are often live streamed. The recordings consist of one-on-one interactions with police, traffic and pedestrian stops and protests.

According to the court records, neither had conducted secret recordings of police and "both have stated that their desire to record secretly stems from a fear that doing so openly will endanger their safety and provoke hostility from officers."

The court ruled those concerns were not without merit.

According to the court, the Suffolk DA's office has opened at least 11 cases involving a felony charge under Mass. General Laws Section 99, including cases where the person being recorded was a police officer. Similarly, the Boston Police Department has applied for criminal complaints against at least nine individuals for secretly recording police performing their duties in public.

In fact, the court said, Boston Police training videos depict two scenarios of citizens recording police -- one openly and one in secret -- instructing officers that the latter is illegal. The video is mandatory viewing for current officers.

"Do these training materials evince a 'conscious choice' by BPD to enforce Section 99?" the court asked. "The answer is yes. Although an individual police officer retains discretion about whether to arrest someone for violating Section 99, the training materials cited above make clear that BPD 'put flesh on the bones' of Section 99 and 'apparently instructed officers that they could make arrests' for what the plaintiffs now claim was constitutionally protected conduct."

Project Veritas cited four different projects it wanted to do in Massachusetts, but said it had refrained from doing due to Massachusetts' law. Potential recordings would have included landlords renting unsafe apartments to college students, government officials to ascertain their positions on sanctuary cities, protest management activities by both government officials and private individuals related to Antifa protests and interactions with Harvard University officials to research its endowment and use of federal funds.

In Saris' decision, the judge referenced a couple of previous cases, including Glik v. Cunniffe in 2011, in which a man was arrested for using his phone's video camera to record police arresting someone on Boston Common. Charges against him were dismissed and the court ruled there was a constitutionally protected right to videotape police carrying out their duties in public.

Saris said an injunction against the Suffolk District Attorney and Boston Police would be issued later.