Вот мой текущий код:
voidprocess_files(const std::string& filePath, const std::string& voiceKey, const std::string& voiceRegion, std::vectorstd::string& Complete_files, std::string file_name)
{
try {
автоматическая речьConfig = SpeechConfig::FromSubscription(speechKey, SpeechRegion); //API КЛЮЧИ
if (!speechConfig)
{
throw std::runtime_error("Не удалось создать речевую конфигурацию."); //сообщение об ошибке
Код: Выделить всё
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]
Мобильная версия