В настоящее время у меня возникла проблема с длительностью транскрипции SDK Azure Speech to Text. Как мне добиться того, чтобы SDK прослужил нужное время, в зависимости от длины файла .wav, и расшифровать всю распознанную речь. В настоящее время, когда я пытаюсь расшифровать аудиофайлы продолжительностью около 32 секунд, я получаю только первое предложение, прежде чем моя программа переходит к следующему файлу.
Вот мой текущий код:
void process_files(const std::string& filePath, const std::string& speechKey, const std::string& speechRegion, std::vector& complete_files, std::string file_name)
{
try {
auto speechConfig = SpeechConfig::FromSubscription(speechKey, speechRegion); //API KEYS
if (!speechConfig)
{
throw std::runtime_error("Failed to create speech configuration."); //error message
}
speechConfig->SetSpeechRecognitionLanguage("en-US"); //set language to english
// Check if the file is a valid WAV file
std::ifstream fileStream(filePath, std::ios::binary);
if (!fileStream)
{
throw std::runtime_error("Failed to open audio file: " + filePath); //file cannot be found in directory
}
// Read the WAV header
char riffHeader[4];
fileStream.read(riffHeader, 4);
if (fileStream.gcount() != 4 || std::strncmp(riffHeader, "RIFF", 4) != 0)
{
throw std::runtime_error("Invalid WAV file header (RIFF header not found): " + filePath); //file is not wav or it is corrupt
}
fileStream.close(); //close file stream
auto audioConfig = AudioConfig::FromWavFileInput(filePath);
if (!audioConfig)
{
throw std::runtime_error("Failed to create audio configuration.");
}
auto speechRecognizer = SpeechRecognizer::FromConfig(speechConfig, audioConfig);
if (!speechRecognizer)
{
throw std::runtime_error("Failed to create speech recognizer.");
}
auto result = speechRecognizer->RecognizeOnceAsync().get();
if (!result)
{
throw std::runtime_error("Recognition result is null.");
}
if (result->Reason == ResultReason::RecognizedSpeech)
{
if (!isComplete(complete_files, file_name) || complete_files.empty())
complete_files.push_back(file_name);
std::cout Reason == ResultReason::NoMatch)
{
if (!isComplete(complete_files, file_name)) //maybe will add seperate vector for files not transcribed
complete_files.push_back(file_name);
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/78514346/azure-speech-text-sdk-c[/url]
В настоящее время у меня возникла проблема с длительностью транскрипции SDK Azure Speech to Text. Как мне добиться того, чтобы SDK прослужил нужное время, в зависимости от длины файла .wav, и расшифровать всю распознанную речь. В настоящее время, когда я пытаюсь расшифровать аудиофайлы продолжительностью около 32 секунд, я получаю только первое предложение, прежде чем моя программа переходит к следующему файлу. Вот мой текущий код: [code]void process_files(const std::string& filePath, const std::string& speechKey, const std::string& speechRegion, std::vector& complete_files, std::string file_name) { try { auto speechConfig = SpeechConfig::FromSubscription(speechKey, speechRegion); //API KEYS if (!speechConfig) { throw std::runtime_error("Failed to create speech configuration."); //error message }
speechConfig->SetSpeechRecognitionLanguage("en-US"); //set language to english
// Check if the file is a valid WAV file std::ifstream fileStream(filePath, std::ios::binary); if (!fileStream) { throw std::runtime_error("Failed to open audio file: " + filePath); //file cannot be found in directory }
// Read the WAV header char riffHeader[4]; fileStream.read(riffHeader, 4); if (fileStream.gcount() != 4 || std::strncmp(riffHeader, "RIFF", 4) != 0) { throw std::runtime_error("Invalid WAV file header (RIFF header not found): " + filePath); //file is not wav or it is corrupt }
fileStream.close(); //close file stream
auto audioConfig = AudioConfig::FromWavFileInput(filePath); if (!audioConfig) { throw std::runtime_error("Failed to create audio configuration."); }
auto speechRecognizer = SpeechRecognizer::FromConfig(speechConfig, audioConfig); if (!speechRecognizer) { throw std::runtime_error("Failed to create speech recognizer."); }
auto result = speechRecognizer->RecognizeOnceAsync().get(); if (!result) { throw std::runtime_error("Recognition result is null."); }
if (result->Reason == ResultReason::RecognizedSpeech) { if (!isComplete(complete_files, file_name) || complete_files.empty()) complete_files.push_back(file_name); std::cout Reason == ResultReason::NoMatch) { if (!isComplete(complete_files, file_name)) //maybe will add seperate vector for files not transcribed complete_files.push_back(file_name); std::cout