Я мигрирую код из пакета V1 в пакет V2. Насколько я могу судить, квоты одинаковы, однако, когда я использую пакет V2 с большими наборами фраз, я получаю ошибку, даже если я разделил фразы на множестве объектов набора фраз. Документация квотов для справки: https://cloud.google.com/speech-to-text ... de]private async Task MinimumReproducibleCode()
{
var builder = new SpeechClientBuilder
{ JsonCredentials = googleServiceAccount.Credential, Endpoint = "us-central1-speech.googleapis.com" };
var speechClient = await builder.BuildAsync();
var recognitionConfig = new RecognitionConfig
{
LanguageCodes = { "en-US" },
Features = new RecognitionFeatures
{
EnableAutomaticPunctuation = true, ProfanityFilter = true
},
ExplicitDecodingConfig = new ExplicitDecodingConfig
{
AudioChannelCount = 1, SampleRateHertz = 8000, Encoding = ExplicitDecodingConfig.Types.AudioEncoding.Mulaw
},
Model = "telephony"
};
var phrases = GenerateRandomPhrases(2500).ToList();
if (phrases.Count > 0)
{
recognitionConfig.Adaptation = CreateSpeechAdaption(phrases);
logger.Info()
.Message($"Phrase set count {recognitionConfig.Adaptation.PhraseSets.Count}");
}
var recognizeStream = speechClient.StreamingRecognize();
var streamingRecognitionConfig = new StreamingRecognitionConfig
{
Config = recognitionConfig,
StreamingFeatures = new StreamingRecognitionFeatures { InterimResults = true }
};
await recognizeStream.WriteAsync(new StreamingRecognizeRequest
{
Recognizer = $"projects/{googleServiceAccount.ProjectId}/locations/us-central1/recognizers/_",
StreamingConfig = streamingRecognitionConfig
});
try
{
while (await recognizeStream.GetResponseStream().MoveNextAsync())
{
var results = recognizeStream.GetResponseStream().Current.Results;
//do stuff here with the results
}
}
catch (Exception exception)
{
logger.Error()
.Exception(exception)
.Message("Error getting transcript results")
.Write();
}
}
private static SpeechAdaptation CreateSpeechAdaption(IEnumerable phrases)
{
var typedPhrases = phrases.Select(p => new PhraseSet.Types.Phrase { Value = p }).ToArray();
var speechAdaption = new SpeechAdaptation();
foreach (var chunk in typedPhrases.Chunk(1200))
speechAdaption.PhraseSets.Add(new SpeechAdaptation.Types.AdaptationPhraseSet
{ InlinePhraseSet = new PhraseSet { Phrases = { chunk }, Boost = 10 } });
return speechAdaption;
}
private IEnumerable GenerateRandomPhrases(int count)
{
var random = new Random();
const string characters = "abcdefghijklmnopqrstuvwxyz";
for (var i = 0; i
Подробнее здесь: https://stackoverflow.com/questions/797 ... sets-or-am