-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added audio generation on word creation - added logs - added results for azure blob
- Loading branch information
1 parent
12461b6
commit b0f0294
Showing
16 changed files
with
325 additions
and
144 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,33 @@ | ||
namespace My1kWordsEe.Models | ||
{ | ||
public class SampleSentence | ||
/// <summary> | ||
/// Sample sentence illustrating the use of a give Estonian word | ||
/// </summary> | ||
public record SampleSentence | ||
{ | ||
public string EeWord { get; set; } | ||
/// <summary> | ||
/// Target Estonian word | ||
/// </summary> | ||
public string EeWord { get; init; } | ||
|
||
public string EeSentence { get; set; } | ||
/// <summary> | ||
/// Illustrative sentence in Estonian | ||
/// </summary> | ||
public string EeSentence { get; init; } | ||
|
||
public string EnSentence { get; set; } | ||
/// <summary> | ||
/// Translation of the illustrative sentence in English | ||
/// </summary> | ||
public string EnSentence { get; init; } | ||
|
||
public Uri EeAudioUrl { get; set; } | ||
/// <summary> | ||
/// Sentence spoken in Estonian | ||
/// </summary> | ||
public Uri EeAudioUrl { get; init; } | ||
|
||
public Uri ImageUrl { get; set; } | ||
/// <summary> | ||
/// Image associated with the sentence | ||
/// </summary> | ||
public Uri ImageUrl { get; init; } | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using CSharpFunctionalExtensions; | ||
|
||
using My1kWordsEe.Services.Db; | ||
|
||
namespace My1kWordsEe.Services.Cqs | ||
{ | ||
public class AddAudioCommand | ||
{ | ||
private readonly TartuNlpService tartuNlpService; | ||
private readonly AzureBlobService azureBlobService; | ||
|
||
public AddAudioCommand( | ||
TartuNlpService tartuNlpService, | ||
AzureBlobService azureBlobService) | ||
{ | ||
this.tartuNlpService = tartuNlpService; | ||
this.azureBlobService = azureBlobService; | ||
} | ||
|
||
public Task<Result<Uri>> Invoke(string text) => | ||
this.tartuNlpService.GetSpeech(text).Bind( | ||
this.azureBlobService.SaveAudio); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using CSharpFunctionalExtensions; | ||
|
||
using My1kWordsEe.Models; | ||
using My1kWordsEe.Services.Db; | ||
|
||
namespace My1kWordsEe.Services.Cqs | ||
{ | ||
public class AddSampleWordCommand | ||
{ | ||
private readonly OpenAiService openAiService; | ||
private readonly AzureBlobService azureBlobService; | ||
private readonly AddAudioCommand addAudioCommand; | ||
|
||
public AddSampleWordCommand( | ||
OpenAiService openAiService, | ||
AzureBlobService azureBlobService, | ||
AddAudioCommand createAudioCommand) | ||
{ | ||
this.azureBlobService = azureBlobService; | ||
this.openAiService = openAiService; | ||
this.addAudioCommand = createAudioCommand; | ||
} | ||
|
||
public async Task<Result<SampleWord>> Invoke(string eeWord) | ||
{ | ||
(await openAiService.GetWordMetadata(eeWord)).Deconstruct( | ||
out bool _, | ||
out bool isAiFailure, | ||
out SampleWord sampleWord, | ||
out string aiError); | ||
|
||
if (isAiFailure) | ||
{ | ||
return Result.Failure<SampleWord>(aiError); | ||
} | ||
|
||
(await this.addAudioCommand.Invoke(eeWord)).Deconstruct( | ||
out bool isAudioSaved, | ||
out bool _, | ||
out Uri audioUri); | ||
|
||
sampleWord = isAudioSaved ? sampleWord with { EeAudioUrl = audioUri } : sampleWord; | ||
|
||
return (await azureBlobService.SaveWordData(sampleWord)).Bind(_ => Result.Of(sampleWord)); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,42 @@ | ||
using CSharpFunctionalExtensions; | ||
|
||
using My1kWordsEe.Models; | ||
using My1kWordsEe.Services.Db; | ||
|
||
namespace My1kWordsEe.Services.Cqs | ||
{ | ||
public class GetOrAddSampleWordCommand | ||
{ | ||
private readonly AzureBlobService azureBlobService; | ||
private readonly AddSampleWordCommand addSampleWordCommand; | ||
|
||
public GetOrAddSampleWordCommand( | ||
AzureBlobService azureBlobService, | ||
AddSampleWordCommand addSampleWordCommand) | ||
{ | ||
this.azureBlobService = azureBlobService; | ||
this.addSampleWordCommand = addSampleWordCommand; | ||
} | ||
|
||
public async Task<Result<SampleWord>> Invoke(string eeWord) | ||
{ | ||
(await azureBlobService.GetWordData(eeWord)).Deconstruct( | ||
out bool _, | ||
out bool isBlobAccessFailure, | ||
out Maybe<SampleWord> savedWord, | ||
out string blobAccessError); | ||
|
||
if (isBlobAccessFailure) | ||
{ | ||
return Result.Failure<SampleWord>(blobAccessError); | ||
} | ||
|
||
if (savedWord.HasValue) | ||
{ | ||
return savedWord.Value; | ||
} | ||
|
||
return await this.addSampleWordCommand.Invoke(eeWord); | ||
} | ||
} | ||
} |
Oops, something went wrong.