@novo-learning/novo-sdk
Version:
SDK for the Novolanguage Speech Analysis API
53 lines (48 loc) • 2.05 kB
text/typescript
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
import { LanguageCodeMapper } from '../../mappers/language-code.mapper';
import { PronunciationRequestDtoV1 } from './dto/pronunciation-request.dto.v1';
import { PhrasePronunciationDtoV1 } from './dto/pronunciation.dto.v1';
import { PhrasePronunciationDtoV2 } from './dto/pronunciation.dto.v2';
import { Configuration, PronunciationApi as GeneratedPronunciationApi } from './generated';
export class PronunciationApi {
private readonly pronunciationApi: GeneratedPronunciationApi;
private readonly languageCodeMapper: LanguageCodeMapper;
constructor(configuration?: Configuration | undefined, basePath?: string, axios?: AxiosInstance) {
this.pronunciationApi = new GeneratedPronunciationApi(configuration, basePath, axios);
this.languageCodeMapper = new LanguageCodeMapper();
}
public getPronunciationsV1(
pronunciationRequest: PronunciationRequestDtoV1,
options?: AxiosRequestConfig<unknown> | undefined,
): Promise<AxiosResponse<PhrasePronunciationDtoV1>> {
return this.pronunciationApi
.getPronunciationsV1(
{
...pronunciationRequest,
targetLanguage: this.languageCodeMapper.mapToGenerated(pronunciationRequest.targetLanguage),
},
options,
)
.then((r) => ({
...r,
data: { ...r.data, language: this.languageCodeMapper.mapFromGenerated(r.data.language) },
}));
}
public getPronunciationsV2(
pronunciationRequest: PronunciationRequestDtoV1,
options?: AxiosRequestConfig<unknown> | undefined,
): Promise<AxiosResponse<PhrasePronunciationDtoV2>> {
return this.pronunciationApi
.getPronunciationsV2(
{
...pronunciationRequest,
targetLanguage: this.languageCodeMapper.mapToGenerated(pronunciationRequest.targetLanguage),
},
options,
)
.then((r) => ({
...r,
data: { ...r.data, language: this.languageCodeMapper.mapFromGenerated(r.data.language) },
}));
}
}