-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from pavel-zhur/feature/audio
dog & dragon: audio transcriptions
- Loading branch information
Showing
15 changed files
with
249 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,4 +39,6 @@ public enum InteractionType | |
ImagesSuccess, | ||
|
||
OwnChatterImageMessage, | ||
|
||
OwnChatterAudio, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
OneShelf.Common/OneShelf.Common.OpenAi/Services/DialogRunner.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
OneShelf.Common/OneShelf.Common.OpenAi/Services/Transcriber.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
using OneShelf.Billing.Api.Client; | ||
using OneShelf.Common.OpenAi.Models; | ||
using OpenAI; | ||
using OpenAI.Audio; | ||
|
||
namespace OneShelf.Common.OpenAi.Services; | ||
|
||
public class Transcriber | ||
{ | ||
private readonly ILogger<Transcriber> _logger; | ||
private readonly BillingApiClient _billingApiClient; | ||
private readonly OpenAIClient _client; | ||
private readonly OpenAiOptions _options; | ||
|
||
public Transcriber(IOptions<OpenAiOptions> options, ILogger<Transcriber> logger, BillingApiClient billingApiClient) | ||
{ | ||
_logger = logger; | ||
_billingApiClient = billingApiClient; | ||
_options = options.Value; | ||
_client = new(new(options.Value.OpenAiApiKey)); | ||
} | ||
|
||
public async Task<string> TranscribeAudio(byte[] audio, DialogConfiguration configuration) | ||
{ | ||
var started = DateTime.Now; | ||
using var stream = new MemoryStream(audio); | ||
var model = "whisper-1"; | ||
var response = await _client.AudioEndpoint.CreateTranscriptionJsonAsync(new(stream, "stream.webm", model, responseFormat: AudioResponseFormat.Verbose_Json)); | ||
_logger.LogInformation("Audio transcribed. Took {ms} ms.", DateTime.Now - started); | ||
await _billingApiClient.Add(new() | ||
{ | ||
Count = (int)Math.Ceiling(response.Duration ?? 0), | ||
UserId = configuration.UserId, | ||
Model = model, | ||
UseCase = configuration.UseCase, | ||
AdditionalInfo = configuration.AdditionalBillingInfo, | ||
DomainId = configuration.DomainId, | ||
ChatId = configuration.ChatId, | ||
}); | ||
|
||
return response.Text; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,6 @@ public enum InteractionType | |
ImagesLimit, | ||
|
||
OwnChatterImageMessage, | ||
|
||
OwnChatterAudio | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.