34.3 Files to text
byte[] bytes = await db.FileDownloadAsync(contract, c => c.Document);
var result = await db.Services.FileToText.ExtractTextAsync(bytes, "contract.pdf", ["nb", "en"]);
string text = result.Text;The file type is found from the content, not the name. The languages, most likely first, help OCR.
You can pass a stream instead of bytes. In the FileToTextResult, Text has lines ending in \n
and pages separated by a form feed (PageTexts splits them). Truncated says the text was cut at a
limit, and Ocr that some of it was read from pictures. Title, Author and Language are what the
file says about itself.
A file type nothing can read is refused with a 415 before anything is charged. GetFormatsAsync()
lists the file types the service reads.
Recordings and videos are transcribed. Timed is then true, Duration is the length in
seconds, and each line of Text starts with when it is spoken:
[00:01:02.500 --> 00:01:05.250] And that is how it began.- For an index, use
TextWithoutTimestamps. For a video player, useToWebVtt()orToSrt(), orCuesfor the lines one by one. - Videos are sent as sound. The service reads sound only, so your server takes the sound out of a video first, with the built-in video converter (FFmpeg, downloaded the first time it is needed). A video format the converter cannot read is refused with a 415. A recording is sent as it is.
- Long recordings (over an hour, on the hosted service) are sent in parts. Each part is charged as a file.