func buildDocument()

in api/contactcenteranalysis/analyze_speech.go [147:172]


func buildDocument(
	ctx context.Context,
	lang string,
	text string,
) (*languagepb.Document, error) {
	var sl *supportedLanguage
	for _, l := range supportedLanguages {
		if l.Code == lang {
			sl = l
			break
		}
	}

	if sl == nil {
		return nil, hd.Errorf(ctx,
			http.StatusBadRequest,
			fmt.Sprintf("%s is not supported", lang),
			"unsupported language code: %s", lang)
	}

	return &languagepb.Document{
		Type:     languagepb.Document_PLAIN_TEXT,
		Source:   &languagepb.Document_Content{Content: text},
		Language: sl.languageCode,
	}, nil
}