Skip to content

Commit

Permalink
v1.5.8
Browse files Browse the repository at this point in the history
spotify connect once
eleven labs api update
  • Loading branch information
VRCWizard authored Oct 7, 2023
1 parent 1a69a95 commit 7c23955
Show file tree
Hide file tree
Showing 13 changed files with 244 additions and 156 deletions.
Binary file modified OSCVRCWiz/App.config
Binary file not shown.
2 changes: 1 addition & 1 deletion OSCVRCWiz/Resources/StartUp/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace OSCVRCWiz.Resources.StartUp
public class Updater
{

public static string currentVersion = "1.5.7.5";
public static string currentVersion = "1.5.8";
public static string updateXMLName = "https://github.com/VRCWizard/TTS-Voice-Wizard/releases/latest/download/AutoUpdater-x64.xml";

public static async void getGithubInfo()
Expand Down
12 changes: 1 addition & 11 deletions OSCVRCWiz/Services/Integrations/Heartrate/HeartratePulsoid.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
using Octokit;
using OSCVRCWiz.Resources.StartUp.StartUp;
using OSCVRCWiz.Services.Integrations.Media;
using OSCVRCWiz.Resources.StartUp.StartUp;
using OSCVRCWiz.Services.Text;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http.Headers;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Markup;


namespace OSCVRCWiz.Services.Integrations.Heartrate
Expand Down
121 changes: 53 additions & 68 deletions OSCVRCWiz/Services/Integrations/Media/SpotifyAddon.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SpotifyAPI.Web.Auth;
using SpotifyAPI.Web;
using OSCVRCWiz.Services.Text;
using OSCVRCWiz.Settings;
using SpotifyAPI.Web;
using SpotifyAPI.Web.Auth;
using System.Diagnostics;
using System.Windows;
using OSCVRCWiz.Resources;
using static System.Net.Mime.MediaTypeNames;
using OSCVRCWiz.Services.Text;
using OSCVRCWiz.RJControls;
using Newtonsoft.Json.Linq;
using System.Text;

namespace OSCVRCWiz.Services.Integrations.Media
{
Expand All @@ -37,7 +28,41 @@ public class SpotifyAddon

public static string previousError = "";

static DateTime tokenExpirationTime;


// check if the token is expired
private static bool IsTokenExpired()
{
if (myPKCEToken != null)
{
// DateTime tokenExpirationTime = DateTime.Now.AddSeconds(myPKCEToken.ExpiresIn);

// OutputText.outputLog("checking if token expired: "+ (tokenExpirationTime <= DateTime.Now).ToString());
return (tokenExpirationTime <= DateTime.Now);
}
else
{
Debug.WriteLine("----- updating tokens -----");
return true;
}
}

// refresh the access token
private static async Task<PKCETokenResponse> RefreshAccessToken()
{
OutputText.outputLog("Debug: Updating Spotify Tokens");
string clientId = legacyState ? clientIdLegacy : Settings1.Default.SpotifyKey;
Debug.WriteLine("----Spotify token refresh Attempt-----");
PKCETokenRefreshRequest refreshRequest = new PKCETokenRefreshRequest(clientId, Settings1.Default.PKCERefreshToken);
PKCETokenResponse refreshResponse = await new OAuthClient().RequestToken(refreshRequest);
myPKCEToken = refreshResponse;
OutputText.outputLog("Debug: Your Spotify Token will refresh in "+((myPKCEToken.ExpiresIn/60)-1)+" minutes");

tokenExpirationTime = DateTime.Now.AddSeconds(myPKCEToken.ExpiresIn-60);
// OutputText.outputLog((DateTime.Now.AddSeconds(myPKCEToken.ExpiresIn - 60) <= DateTime.Now).ToString());
return refreshResponse;
}

public static async Task spotifyGetCurrentSongInfo()
{
Expand All @@ -48,34 +73,22 @@ public static async Task spotifyGetCurrentSongInfo()
if (myClient == null)
{
myClient = new SpotifyClient(Settings1.Default.PKCEAccessToken);

}
if (myClient != null)
else
{
try
{
if (legacyState == true)
bool tokenExpired = IsTokenExpired();
if (tokenExpired)
{
Debug.WriteLine("----Spotify token refreshed Attempt-----");
PKCETokenRefreshRequest refreshRequest = new PKCETokenRefreshRequest(clientIdLegacy, Settings1.Default.PKCERefreshToken);
PKCETokenResponse refreshResponse = await new OAuthClient().RequestToken(refreshRequest);
Debug.WriteLine("----Spotify token needs refreshing-----");
PKCETokenResponse refreshResponse = await RefreshAccessToken();
myClient = new SpotifyClient(refreshResponse.AccessToken);
Settings1.Default.PKCERefreshToken = refreshResponse.RefreshToken;
Settings1.Default.PKCEAccessToken = refreshResponse.AccessToken;
Settings1.Default.Save();
Debug.WriteLine("----Spotify token refreshed Successful-----");
}
else
{
string clientId = Settings1.Default.SpotifyKey;
Debug.WriteLine("----Spotify token refreshed Attempt-----");
PKCETokenRefreshRequest refreshRequest = new PKCETokenRefreshRequest(clientId, Settings1.Default.PKCERefreshToken);
PKCETokenResponse refreshResponse = await new OAuthClient().RequestToken(refreshRequest);
myClient = new SpotifyClient(refreshResponse.AccessToken);
Settings1.Default.PKCERefreshToken = refreshResponse.RefreshToken;
Settings1.Default.PKCEAccessToken = refreshResponse.AccessToken;
Settings1.Default.Save();
Debug.WriteLine("----Spotify token refreshed Successful-----");

Debug.WriteLine("----Spotify token refreshed Successfully-----");
}

if (spotifyConnect == false)
Expand All @@ -89,7 +102,7 @@ public static async Task spotifyGetCurrentSongInfo()

catch (APIException ex)
{
Debug.WriteLine("-----Spotify token doesn't need to refresh-----" + ex.Response.Body.ToString());
Debug.WriteLine("-----Spotify error-----" + ex.Response.Body.ToString());

}
FullTrack m_currentTrack;
Expand Down Expand Up @@ -478,27 +491,8 @@ public static async Task SpotifyConnect()
globalVerifier = verifier;

// var loginRequest = new LoginRequest(_server.BaseUri, clientId,LoginRequest.ResponseType.Code)
if (legacyState == true)
{
var loginRequest = new LoginRequest(_server.BaseUri, clientIdLegacy, LoginRequest.ResponseType.Code)
{
CodeChallengeMethod = "S256",
CodeChallenge = challenge,
Scope = new[] { Scopes.UserReadCurrentlyPlaying, Scopes.UserReadPlaybackState }
};
// BrowserUtil.Open(loginRequest.ToUri());
string url = loginRequest.ToUri().ToString();
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });//this link doesnt like the other method
if (VoiceWizardWindow.MainFormGlobal.rjToggleShowConnectURISpotify.Checked)
{
OutputText.outputLog(loginRequest.ToUri().ToString());
}

}
else
{
string clientId = Settings1.Default.SpotifyKey;
var loginRequest = new LoginRequest(_server.BaseUri, clientId, LoginRequest.ResponseType.Code)
string clientId = legacyState ? clientIdLegacy : Settings1.Default.SpotifyKey;
var loginRequest = new LoginRequest(_server.BaseUri, clientId, LoginRequest.ResponseType.Code)
{
CodeChallengeMethod = "S256",
CodeChallenge = challenge,
Expand All @@ -514,32 +508,23 @@ public static async Task SpotifyConnect()
OutputText.outputLog(loginRequest.ToUri().ToString());
}

}



}

// This method should be called from your web-server when the user visits "http://localhost:5000/callback"
public static async Task GetCallback(object sender, AuthorizationCodeResponse response)
public static async Task GetCallback(object sender, AuthorizationCodeResponse response) //this function gets and saves the
{
Debug.WriteLine("Getcallback code: " + response.Code.ToString());

if (legacyState == true)
{
var initialResponse = await new OAuthClient().RequestToken(new PKCETokenRequest(clientIdLegacy, response.Code, new Uri("http://localhost:5000/callback"), globalVerifier));
Settings1.Default.PKCERefreshToken = initialResponse.RefreshToken;
Settings1.Default.PKCEAccessToken = initialResponse.AccessToken;
Settings1.Default.Save();

}
else
{
string clientId = Settings1.Default.SpotifyKey;
string clientId = legacyState ? clientIdLegacy : Settings1.Default.SpotifyKey;
var initialResponse = await new OAuthClient().RequestToken(new PKCETokenRequest(clientId, response.Code, new Uri("http://localhost:5000/callback"), globalVerifier));
Settings1.Default.PKCERefreshToken = initialResponse.RefreshToken;
Settings1.Default.PKCEAccessToken = initialResponse.AccessToken;
Settings1.Default.Save();
}



}
public static string Base64Encode(string plainText)
Expand Down
15 changes: 1 addition & 14 deletions OSCVRCWiz/Services/Integrations/OSCListener.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CoreOSC;
using CoreOSC;
using OSCVRCWiz.Resources.StartUp.StartUp;
using OSCVRCWiz.RJControls;
using OSCVRCWiz.Services.Speech.TextToSpeech;
using OSCVRCWiz.Services.Text;
using OSCVRCWiz.Settings;



Expand Down Expand Up @@ -51,12 +44,6 @@ public class OSCListener
public static void OnStartUp()
{

if (VoiceWizardWindow.MainFormGlobal.rjToggleActivatePulsoidStart.Checked == true)//turn on osc listener on start
{
Task.Run(() => OSCListener.OSCRecieveHeartRate());
}


if (VoiceWizardWindow.MainFormGlobal.rjToggleActivateOSCListenerStart.Checked == true)//turn on osc listener on start
{
Task.Run(() => OSCListener.OSCRecieveHeartRate());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
using OSCVRCWiz.Services.Speech.TextToSpeech;
using OSCVRCWiz.Services.Text;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.WebSockets;
using System.Text;
using System.Threading.Tasks;

namespace OSCVRCWiz.Services.Speech.Speech_Recognition
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public static async Task<Stream> CallElevenLabsAPIAsync(string textIn, string vo
int optimize = 0;
int stabilities = 0;
int similarities = 0;
int styles = 0;
bool boost = true;
string modelID = "eleven_monolingual_v1";
VoiceWizardWindow.MainFormGlobal.Invoke((MethodInvoker)delegate ()
{
Expand All @@ -64,6 +66,8 @@ public static async Task<Stream> CallElevenLabsAPIAsync(string textIn, string vo
stabilities = VoiceWizardWindow.MainFormGlobal.trackBarStability.Value;
similarities = VoiceWizardWindow.MainFormGlobal.trackBarSimilarity.Value;
modelID = VoiceWizardWindow.MainFormGlobal.comboBoxLabsModelID.SelectedItem.ToString();
styles = VoiceWizardWindow.MainFormGlobal.trackBarStyleExaggeration.Value;
boost= VoiceWizardWindow.MainFormGlobal.rjToggleSpeakerBoost.Checked;

Debug.WriteLine(optimize);
Debug.WriteLine(stabilities);
Expand All @@ -76,6 +80,7 @@ public static async Task<Stream> CallElevenLabsAPIAsync(string textIn, string vo

var similarityFloat = similarities * 0.01f;
var stabilityFloat = stabilities * 0.01f;
var styleFloat = styles * 0.01f;

var url = $"https://api.elevenlabs.io/v1/text-to-speech/{voice}?optimize_streaming_latency={optimize}";
// var url = $"https://api.elevenlabs.io/v1/text-to-speech/{voice}";
Expand All @@ -90,7 +95,9 @@ public static async Task<Stream> CallElevenLabsAPIAsync(string textIn, string vo
voice_settings = new
{
stability = stabilityFloat,
similarity_boost = similarityFloat
similarity_boost = similarityFloat,
style = styleFloat,
use_speaker_boost = boost
}
});

Expand Down
4 changes: 4 additions & 0 deletions OSCVRCWiz/Settings/LoadSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ public static void LoadingSettings()
VoiceWizardWindow.MainFormGlobal.trackBarSimilarity.Value = Settings1.Default.labsSimboost;
VoiceWizardWindow.MainFormGlobal.trackBarStability.Value = Settings1.Default.labsStability;

VoiceWizardWindow.MainFormGlobal.trackBarStyleExaggeration.Value = Settings1.Default.labsStyleExagg;
VoiceWizardWindow.MainFormGlobal.rjToggleSpeakerBoost.Checked = Settings1.Default.labsSpeakerBoost;


VoiceWizardWindow.MainFormGlobal.rjToggleButtonSaveToWav.Checked = Settings1.Default.saveToWav;

VoiceWizardWindow.MainFormGlobal.labelTTSCharacters.Text = Settings1.Default.charsUsed;
Expand Down
2 changes: 2 additions & 0 deletions OSCVRCWiz/Settings/SaveSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ public static void SavingSettings()
Settings1.Default.labsOptimize = VoiceWizardWindow.MainFormGlobal.comboBoxLabsOptimize.SelectedIndex;
Settings1.Default.labsSimboost = VoiceWizardWindow.MainFormGlobal.trackBarSimilarity.Value;
Settings1.Default.labsStability = VoiceWizardWindow.MainFormGlobal.trackBarStability.Value;
Settings1.Default.labsStyleExagg = VoiceWizardWindow.MainFormGlobal.trackBarStyleExaggeration.Value;
Settings1.Default.labsSpeakerBoost = VoiceWizardWindow.MainFormGlobal.rjToggleSpeakerBoost.Checked;

Settings1.Default.saveToWav = VoiceWizardWindow.MainFormGlobal.rjToggleButtonSaveToWav.Checked;

Expand Down
26 changes: 25 additions & 1 deletion OSCVRCWiz/Settings/Settings1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion OSCVRCWiz/Settings/Settings1.settings
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@
<Value Profile="(Default)">75</Value>
</Setting>
<Setting Name="labsStability" Type="System.Int32" Scope="User">
<Value Profile="(Default)">75</Value>
<Value Profile="(Default)">50</Value>
</Setting>
<Setting Name="saveToWav" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
Expand Down Expand Up @@ -614,5 +614,11 @@
<Setting Name="showSpotifyURi" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="labsStyleExagg" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="labsSpeakerBoost" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
Loading

0 comments on commit 7c23955

Please sign in to comment.