Following code works as expected in powershell 5.1:
function Get-Say([String] $Message, [String] $Voice = "Microsoft Irina Desktop") {
Add-Type -Ass
This is a known issue and is due to the fact that some of the functionality required is not present in .NET Core, which PS v7 is built on. Looks like a bug was raised but it was closed without a fix:
System.Speech.Synthesis.SpeechSynthesizer Speak method throws Object reference not set to an instance of an object." in PowerShell 6.1.2