using System;
using System.Drawing;
public static class VoiceBotScript
{
// Parametters
private const uint WM_KEYDOWN = 0x0100;
private const uint WM_KEYUP = 0x0101;
private const uint VK_SPACE = 0x20;
private const uint L_Param1 = 0x390001;
private const uint L_Param2 = 0xC0390001;
private const uint eka = 0x93;
private const uint toka = 0x0;
private const uint kolmas = 0x19f07c;
private const uint eka2 = 0xAE;
private const uint toka2 = 0x8;
private const uint kolmas2 = 0x0;
private const uint eka3 = 0x93;
private const uint toka3 = 0x0;
private const uint kolmas3 = 0x19eddc;
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "PostMessage")]
static extern int PostMessage(IntPtr hwnd, uint msg, uint wParam, uint lParam);
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SendMessage")]
static extern int SendMessage(IntPtr hwnd, uint msg, uint wParam, uint lParam);
public static void Run(IntPtr windowHandle)
{
// your code goes here
IntPtr spotify = BFS.Window.GetWindowByText("Spotify*");
string teksti = spotify.ToString(); //muutetaan Stringiksi!
//BFS.Dialog.ShowMessageInfo(teksti); //debuggeri tulostus
string spotifyMain = BFS.Window.GetClass(spotify);
//BFS.Dialog.ShowMessageInfo(spotifyMain);
IntPtr spotifyChild1 = BFS.Window.GetChildWindowByClass(spotify, "CefBrowserWindow");
string teksti2 = spotifyChild1.ToString(); //muutetaan Stringiksi!
//BFS.Dialog.ShowMessageInfo(teksti2);
IntPtr spotifyChild2 = BFS.Window.GetChildWindowByClass(spotifyChild1, "Chrome_WidgetWin_0");
string teksti3 = spotifyChild2.ToString(); //muutetaan Stringiksi!
//BFS.Dialog.ShowMessageInfo(teksti3);
//bool spotifyIkkuna = BFS.Window.Focus(spotify); focucksen vaihto spotifyym
//bool ok = BFS.Input.SendKeys("^({VK_38})"); haluttu toiminto kun focus on vaihtunut
SendMessage(spotify, eka, toka, kolmas);
SendMessage(spotify, eka2, toka2, kolmas2);
SendMessage(spotify, eka3, toka3, kolmas3);
System.Threading.Thread.Sleep(100);
PostMessage(spotifyChild2, WM_KEYDOWN, VK_SPACE, L_Param1);
System.Threading.Thread.Sleep(100);
PostMessage(spotifyChild2, WM_KEYUP, VK_SPACE, L_Param2);
}
}...
private enum WindowShowStyle : uint
{
/// <summary>Hides the window and activates another window.</summary>
/// <remarks>See SW_HIDE</remarks>
Hide = 0,
/// <summary>Activates and displays a window. If the window is minimized
/// or maximized, the system restores it to its original size and
/// position. An application should specify this flag when displaying
/// the window for the first time.</summary>
/// <remarks>See SW_SHOWNORMAL</remarks>
ShowNormal = 1,
/// <summary>Activates the window and displays it as a minimized window.</summary>
/// <remarks>See SW_SHOWMINIMIZED</remarks>
ShowMinimized = 2,
/// <summary>Activates the window and displays it as a maximized window.</summary>
/// <remarks>See SW_SHOWMAXIMIZED</remarks>
ShowMaximized = 3,
/// <summary>Maximizes the specified window.</summary>
/// <remarks>See SW_MAXIMIZE</remarks>
Maximize = 3,
/// <summary>Displays a window in its most recent size and position.
/// This value is similar to "ShowNormal", except the window is not
/// actived.</summary>
/// <remarks>See SW_SHOWNOACTIVATE</remarks>
ShowNormalNoActivate = 4,
/// <summary>Activates the window and displays it in its current size
/// and position.</summary>
/// <remarks>See SW_SHOW</remarks>
Show = 5,
/// <summary>Minimizes the specified window and activates the next
/// top-level window in the Z order.</summary>
/// <remarks>See SW_MINIMIZE</remarks>
Minimize = 6,
/// <summary>Displays the window as a minimized window. This value is
/// similar to "ShowMinimized", except the window is not activated.</summary>
/// <remarks>See SW_SHOWMINNOACTIVE</remarks>
ShowMinNoActivate = 7,
/// <summary>Displays the window in its current size and position. This
/// value is similar to "Show", except the window is not activated.</summary>
/// <remarks>See SW_SHOWNA</remarks>
ShowNoActivate = 8,
/// <summary>Activates and displays the window. If the window is
/// minimized or maximized, the system restores it to its original size
/// and position. An application should specify this flag when restoring
/// a minimized window.</summary>
/// <remarks>See SW_RESTORE</remarks>
Restore = 9,
/// <summary>Sets the show state based on the SW_ value specified in the
/// STARTUPINFO structure passed to the CreateProcess function by the
/// program that started the application.</summary>
/// <remarks>See SW_SHOWDEFAULT</remarks>
ShowDefault = 10,
/// <summary>Windows 2000/XP: Minimizes a window, even if the thread
/// that owns the window is hung. This flag should only be used when
/// minimizing windows from a different thread.</summary>
/// <remarks>See SW_FORCEMINIMIZE</remarks>
ForceMinimized = 11
}
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool ShowWindow(IntPtr hWnd, WindowShowStyle nCmdShow);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetForegroundWindow(IntPtr hWnd);
...using System;
using System.Drawing;
using System.Linq;
using System.Speech.Recognition.SrgsGrammar;
using System.Speech.Recognition;
using System.Xml;
using SpotifyAPI.Local;
// Add to references | System.Core.dll | C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Speech.dll
// and | YourPathToSpotifyApi\SpotifyApi.dll from (https://github.com/JohnnyCrazy/SpotifyAPI-NET/releases/latest)
public static class VoiceBotScript
{
public static void Run(IntPtr windowHandle)
{
// Path to open\save Volume.xml
var dirPath = @"C:\Test\";
// Open\save srgs file
var srgsFile = SrgsCreator.GetFileWithVolume(dirPath);
// Get recognition result
var volumeRecogResult = SpeechRecognition.Recognition(srgsFile);
BFS.General.ThreadWait(1000);
// Show what recognize. For testing. Can be removed
BFS.Dialog.ShowMessageInfo(volumeRecogResult.ToString());
// Set volume. Values in range 0-100 float
var spLocalApi = new SpotifyLocalAPI();
spLocalApi.SetSpotifyVolume(volumeRecogResult);
}
}
// Speech recognition using a srgs file
class SpeechRecognition
{
public static float Recognition(string volumeList)
{
var volumeRecogResult = "";
var sre = new SpeechRecognitionEngine();
var grammar = new Grammar(volumeList);
sre.LoadGrammar(grammar);
try
{
sre.SetInputToDefaultAudioDevice();
var result = sre.Recognize();
if (result != null)
volumeRecogResult = result.Text;
else
Recognition(volumeList);
}
catch (NullReferenceException ex)
{
BFS.Dialog.ShowMessageError(ex.Message);
}
finally
{
sre.UnloadGrammar(grammar);
}
return float.Parse(volumeRecogResult);
}
}
// Create basic srgs file without regard to pronunciation
class SrgsCreator
{
public static string GetFileWithVolume(string dirPath)
{
var volumeFile = dirPath + "Volume.xml";
if (System.IO.File.Exists(volumeFile))
return volumeFile;
var choices = new Choices();
var volArr = Enumerable.Range(1, 100).ToArray();
foreach (var num in volArr)
choices.Add(num.ToString());
var grammarBuilder = new GrammarBuilder();
grammarBuilder.Append(choices);
var srgsDoc = new SrgsDocument(grammarBuilder);
var xmlWriter = XmlWriter.Create(volumeFile);
srgsDoc.WriteSrgs(xmlWriter);
xmlWriter.Close();
return volumeFile;
}
}using System;
using System.Drawing;
using System.Linq;
using System.Speech.Recognition.SrgsGrammar;
using System.Speech.Recognition;
using System.Xml;
// Add to references | System.Core.dll | C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Speech.dll
public static class VoiceBotScript
{
public static void Run(IntPtr windowHandle)
{
// Path to open\save Volume.xml
var dirPath = @"c:\Test\";
// Open\save srgs file
var srgsFile = SrgsCreator.GetFileWithVolume(dirPath);
// Get recognition result
SpeechRecognition.Recognition(srgsFile);
}
}
class SpeechRecognition
{
public static void Recognition(string volumeList)
{
var volumeRecogResult = "";
var sre = new SpeechRecognitionEngine();
var grammar = new Grammar(volumeList);
sre.LoadGrammar(grammar);
var rr = sre.EmulateRecognize("78");
if (rr != null && rr.Text != null)
BFS.Dialog.ShowMessageInfo("Recognized: " + rr.Text);
}
}
// Create basic srgs file without regard to pronunciation
class SrgsCreator
{
public static string GetFileWithVolume(string dirPath)
{
var volumeFile = dirPath + "Volume.xml";
if (System.IO.File.Exists(volumeFile))
return volumeFile;
var choices = new Choices();
var volArr = Enumerable.Range(1, 100).ToArray();
foreach (var num in volArr)
choices.Add(num.ToString());
var grammarBuilder = new GrammarBuilder();
grammarBuilder.Append(choices);
var srgsDoc = new SrgsDocument(grammarBuilder);
var xmlWriter = XmlWriter.Create(volumeFile);
srgsDoc.WriteSrgs(xmlWriter);
xmlWriter.Close();
return volumeFile;
}
}using System;
using System.Drawing;
using System.Linq;
using System.Speech.Recognition.SrgsGrammar;
using System.Speech.Recognition;
using System.Xml;
using System.Globalization;
using SpotifyAPI.Local;
// Add to references | System.Core.dll | C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\System.Speech.dll
// and | YourPathToSpotifyApi\SpotifyApi.dll from (https://github.com/JohnnyCrazy/SpotifyAPI-NET/releases/latest)
public static class VoiceBotScript
{
public static void Run(IntPtr windowHandle)
{
// Set your recognition language. Support languages: en-GB, en-US, de-DE, es-ES, fr-FR, ja-JP, zh-CN, zh-TW.
var culture = new CultureInfo("en-US");
// Path to open\save Volume.xml
var dirPath = @"c:\Test\";
// Open\save srgs file
var srgsFile = SrgsCreator.GetFileWithVolume(dirPath);
// Get recognition result
var volumeRecogResult = SpeechRecognition.Recognition(srgsFile, culture);
BFS.General.ThreadWait(3000);
// Show what recognize. For testing. Can be removed
//BFS.Dialog.ShowMessageInfo(volumeRecogResult.ToString());
BFS.Speech.TextToSpeech(string.Format("Set volume to {0}", volumeRecogResult));
// Set volume. Values in range 0-100 float
var spLocalApi = new SpotifyLocalAPI();
spLocalApi.SetSpotifyVolume(volumeRecogResult);
}
}
class SpeechRecognition
{
public static float Recognition(string srgsFile, CultureInfo culture)
{
var volumeRecogResult = "";
var sre = new SpeechRecognitionEngine(culture);
var grammar = new Grammar(srgsFile);
sre.LoadGrammar(grammar);
try
{
sre.SetInputToDefaultAudioDevice();
var result = sre.Recognize();
if (result != null)
volumeRecogResult = result.Text;
else
Recognition(srgsFile, culture);
}
catch (NullReferenceException ex)
{
BFS.Dialog.ShowMessageError(ex.Message);
}
finally
{
sre.UnloadGrammar(grammar);
}
return float.Parse(volumeRecogResult);
}
}
// Create basic srgs file without regard to pronunciation
class SrgsCreator
{
public static string GetFileWithVolume(string dirPath)
{
var volumeFile = dirPath + "Volume.xml";
if (System.IO.File.Exists(volumeFile))
return volumeFile;
var choices = new Choices();
var volArr = Enumerable.Range(1, 100).ToArray();
foreach (var num in volArr)
choices.Add(num.ToString());
var grammarBuilder = new GrammarBuilder();
grammarBuilder.Append(choices);
var srgsDoc = new SrgsDocument(grammarBuilder);
var xmlWriter = XmlWriter.Create(volumeFile);
srgsDoc.WriteSrgs(xmlWriter);
xmlWriter.Close();
return volumeFile;
}
}