2

I want to have something that speaks the name of the currently playing track in foobar, best I could come up with is using WSH Panel to launch a powershell text to speech script, however I can't get the track name in WSH Panel..my WSH Panel script looks like:

function on_playback_starting(cmd, is_paused) {

var track_path = fb.TitleFormat("%title%");
WSH = new ActiveXObject("WScript.Shell");

WSH.run("powershell.exe -noexit -ExecutionPolicy ByPass -f c:\\users\\jrg26\\documents\\windowspowershell\\text2speech.ps1 \"test " + track_path+" test part 2\"");
}

It speaks the test "test" and "test part 2", but not the track name. It's not even passing it through, as I have the script set to echo the arguments, and it just displays "test test part 2" for every song. So how do I pass the track name in the way I am attempting?

nixda
  • 27,634

1 Answers1

1

I still had a minor issue and forgot to put an answer when I fixed it. Thanks and I hope someone can find it useful:

Speaks artist+album+track name, cleans up the text so it won't speak unnecessary stuff:

function replace_it(str)
{
str = str.replace(",","(")
str = str.replace("-","(")
str = str.replace(")","(")
str = str.replace("[","(")
str = str.replace("]","(")
str = str.replace("\\","(")
str = str.replace("/","(")
str = str.replace(":","(")
var str_index = str.indexOf("(")
if (str_index != -1)
{
    str = str.substring(0,str_index)
}
return str    
}

function on_playback_new_track(metadb) {
WSH = new ActiveXObject("WScript.Shell");

var artist = fb.TitleFormat("%artist%").Eval(true)
var album = fb.TitleFormat("%album%").Eval(true)
var track_name = fb.TitleFormat("%Title%").Eval(true);

artist = replace_it(artist)
album = replace_it(album)
track_name = replace_it(track_name)

track_path="Artist "+artist+" Album " +album+" track name "+ track_name

fb.Pause()
WSH.run("powershell.exe -nologo -NonInteractive -ExecutionPolicy ByPass -WindowStyle Hidden  -f c:\\users\\jrg26\\documents\\windowspowershell\\text2speech.ps1 \"" + track_path + "\"",0,true);
fb.play()

}

And the powershell script, in case anybody wants this solution:

if ($args.count -gt 0)
{
    echo $args[0]
    Add-Type -AssemblyName System.speech
    $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
    $speak.Speak($args[0])
}

You can increase and lower the rate of the voice as well. Type $speak|get-member, to get a list of properties and methods after you add the type and create the object:

Rate                          Property   int Rate {get;set;}
Voice                         Property   System.Speech.Synthesis.VoiceInfo     Voice {get;}
Volume                        Property   int Volume {get;set;}
SelectVoice                   Method     void SelectVoice(string name)  
SelectVoiceByHints            Method     void       SelectVoiceByHints(System.Speech.Synthesis.VoiceGender gender),

$speak.rate = -5

changes rate to -5, goes from -10 to 10.

$speak.selectvoicebyhints("female")

changes to the US female voice.