openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.9.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

examples/Audio/Example01_SimpleTextToSpeech.cs

26lines · modeblame

8cc6643fJose Arriaga Maldonado2 years ago1using NUnit.Framework;
2using OpenAI.Audio;
3using System;
4using System.IO;
5
6namespace OpenAI.Examples;
7
8public partial class AudioExamples
9{
10[Test]
11public void Example01_SimpleTextToSpeech()
12{
13AudioClient client = new("tts-1", Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
14
15string input = "Overwatering is a common issue for those taking care of houseplants. To prevent it, it is"
16+ " crucial to allow the soil to dry out between waterings. Instead of watering on a fixed schedule,"
17+ " consider using a moisture meter to accurately gauge the soil’s wetness. Should the soil retain"
18+ " moisture, it is wise to postpone watering for a couple more days. When in doubt, it is often safer"
19+ " to water sparingly and maintain a less-is-more approach.";
20
d84bf54dTravis Wilson1 years ago21BinaryData speech = client.GenerateSpeech(input, GeneratedSpeechVoice.Alloy);
8cc6643fJose Arriaga Maldonado2 years ago22
23using FileStream stream = File.OpenWrite($"{Guid.NewGuid()}.mp3");
24speech.ToStream().CopyTo(stream);
25}
26}