Exemple #1
0
        /// <summary>
        /// Common routine for transcribing an audio file.
        /// </summary>
        /// <param name="apiKey">The subscription key.</param>
        /// <param name="region">The region of the resource.</param>
        /// <param name="audioFilePath">The public URI of the audio file to transcribe.</param>
        /// <param name="isUri">Specifies if the <paramref name="audioFilePath"/> is a URI (true) or local file path (false).</param>
        /// <param name="httpClient">The implementation of IHttpClientWrapper to use when making transcription requests.</param>
        /// <param name="log">Trace logger instance.</param>
        /// <returns>A Task returning the transcribed speech.</returns>
        private async Task <string> TranscribeAudioPublicUriCommonAsync(Secret apiKey, string region, string audioFilePath, bool isUri, IHttpClientWrapper httpClient, ILogger log)
        {
            _log = log;
            _transcriptBuilder = new StringBuilder();
            _stopRecognition   = new TaskCompletionSource <int>();

            using (BinaryReader binaryReader = BinaryReaderFactory.GetBinaryReader(audioFilePath, isUri, httpClient, log))
            {
                return(await TranscribeAudioCommonAsync(apiKey, region, binaryReader));
            }
        }
Exemple #2
0
        /// <summary>
        /// Common routine for transcribing an audio file.
        /// </summary>
        /// <param name="apiKey">The subscription key.</param>
        /// <param name="region">The region of the resource.</param>
        /// <param name="audioFileUri">The public URI of the audio file to transcribe.</param>
        /// <param name="storageClient">The implementation of IStorageClient to use when reading the audio file from a source data store.</param>
        /// <param name="storageConnectionString">The connection string to use when connecting the source data store.</param>
        /// <param name="storageContainerName">The container containing the audio file.</param>
        /// <param name="log">Trace logger instance.</param>
        /// <returns>A Task returning the transcribed speech.</returns>
        private async Task <string> TranscribeAudioStorageUriCommonAsync(Secret apiKey, string region, string audioFileUri, IStorageClient storageClient, Secret storageConnectionString, string storageContainerName, ILogger log)
        {
            _log = log;
            _transcriptBuilder = new StringBuilder();
            _stopRecognition   = new TaskCompletionSource <int>();

            using (MemoryStream outputStream = new MemoryStream())
            {
                using (BinaryReader binaryReader = BinaryReaderFactory.GetBinaryReader(audioFileUri, outputStream, storageClient, storageConnectionString, storageContainerName, log))
                {
                    return(await TranscribeAudioCommonAsync(apiKey, region, binaryReader));
                }
            }
        }