hi this is my task 'My Task' async Task TTS(string voiceId, string Text) { // Construct…
- User
hi this is my task
'My Task' async Task TTS(string voiceId, string Text) { // Construct your request object including the new voice ID var request = new { model = "Zyphra/Zonos-v0.1-transformer", input = Text, language = "en-us", voice = voiceId, // Use the voice ID received speed = 0.9f, emotion = new { happiness = 0.0f, sadness = 1.0f, disgust = 0.1f, fear = 0.2f, surprise = 0.1f, anger = 0.2f, other = 0.2f, neutral = 0.1f }, response_format = "wav" };
code// Serialize the request object into JSON var json = JsonConvert.SerializeObject(request); var content = new StringContent(json, Encoding.UTF8, "application/json"); try { // Send a POST request to the speech generation endpoint var response = await MyClient.PostAsync($"{baseUrl}/v1/audio/speech", content); response.EnsureSuccessStatusCode(); // Read the response content as a stream var audioStream = await response.Content.ReadAsStreamAsync(); // Specify the output path for the generated audio var outputFilePath = @"H:\Hot\Pookie\Poo\poo\api\zonos.git\app\audio.wav"; // Update this to .wav extension // Save the audio stream to a file using (var fileStream = new FileStream(outputFilePath, FileMode.Create, FileAccess.Write)) { await audioStream.CopyToAsync(fileStream); } duration = GetWaveFileDuration(outputFilePath); audioFilePath = outputFilePath; PlayAudio(ISim, duration, false); } catch (HttpRequestException e) { MessageBox.Show("Error sending request to the speech generation server:\n" + e.Message); } catch (TaskCanceledException e) { MessageBox.Show("The request timed out:\n" + e.Message); } catch (Exception ex) { MessageBox.Show("An unexpected error occurred:\n" + ex.Message); }}
- Assistant