1

クライアント ライブラリの Google Cloud を実装したいのですが、Ionic の実装がありません。

Google Speech To Text を使用するために Ionic にクライアント ライブラリを実装するにはどうすればよいですか?

今のところ、NodeJS クライアント ライブラリを実装しようとしましたが、フォーラムの一部の人々が、Ionic の File ネイティブ実装を使用する必要があると言っているため、いくつかの問題があります。File を使用するとエラーが発生します。

import {Injectable} from '@angular/core';
import {GoogleSpeechToText} from '@google-cloud/speech';
import {Observable} from 'rxjs';
import {Idea} from './idea.service';
import {File} from '@ionic-native/file/ngx';


@Injectable({
    providedIn: 'root'
})
export class GoogleSpeechToTextService {

    private ideas: Observable<Idea[]>;
    constructor(private GoogleSpeech: GoogleSpeechToText, private MyFile: File) {
    }

    async SpeechClient() {
        // @ts-ignore
        const client = new this.SpeechClient();
        const filename = './resources/audio/audio.raw';

        const file = File.readFileSync(filename);

        const audioBytes = file.toString('base64');
        const audio = {
            content: audioBytes
        };

        const config = {
            encoding: 'LINEAR16',
            sampleRateHertz: 1600,
            languageCode: 'en-US'
        };

        // @ts-ignore
        // @ts-ignore
        const request = {
            audio,
          config,
        };
        const [response] = await client.recognize(request);
        const transcription = response.results.map(result => result.alternative[0].transcript).join('\n');

    }
}

ERROR in ./node_modules/google-gax/build/src/operationsClient.js
Module not found: Error: Can't resolve './operations_client_config' in 'C:\Users\gdemay\Documents\Mobile-Hybrid2\node_modules\google-gax\build\src'
ERROR in ./node_modules/google-auth-library/build/src/auth/googleauth.js
Module not found: Error: Can't resolve 'child_process' in 'C:\Users\gdemay\Documents\Mobile-Hybrid2\node_modules\google-auth-library\build\src\auth'
ERROR in ./node_modules/google-auth-library/build/src/auth/googleauth.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\gdemay\Documents\Mobile-Hybrid2\node_modules\google-auth-library\build\src\auth'
ERROR in ./node_modules/google-p12-pem/build/src/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\gdemay\Documents\Mobile-Hybrid2\node_modules\google-p12-pem\build\src'
ERROR in ./node_modules/gtoken/build/src/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\gdemay\Documents\Mobile-Hybrid2\node_modules\gtoken\build\src'
ERROR in ./node_modules/request/lib/har.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\gdemay\Documents\Mobile-Hybrid2\node_modules\request\lib'
ERROR in ./node_modules/forever-agent/index.js
Module not found: Error: Can't resolve 'net' in 'C:\Users\gdemay\Documents\Mobile-Hybrid2\node_modules\forever-agent'
ERROR in ./node_modules/gaxios/node_modules/https-proxy-agent/index.js
Module not found: Error: Can't resolve 'net' in 'C:\Users\gdemay\Documents\Mobile-Hybrid2\node_modules\gaxios\node_modules\https-proxy-agent'
ERROR in ./node_modules/http-proxy-agent/index.js
Module not found: Error: Can't resolve 'net' in 'C:\Users\gdemay\Documents\Mobile-Hybrid2\node_modules\http-proxy-agent'
ERROR in ./node_modules/teeny-request/node_modules/https-proxy-agent/index.js
Module not found: Error: Can't resolve 'net' in 'C:\Users\gdemay\Documents\Mobile-Hybrid2\node_modules\teeny-request\node_modules\https-proxy-agent'
ERROR in ./node_modules/tough-cookie/lib/cookie.js
Module not found: Error: Can't resolve 'net' in 'C:\Users\gdemay\Documents\Mobile-Hybrid2\node_modules\tough-cookie\lib'
ERROR in ./node_modules/tunnel-agent/index.js
Module not found: Error: Can't resolve 'net' in 'C:\Users\gdemay\Documents\Mobile-Hybrid2\node_modules\tunnel-agent'
ERROR in ./node_modules/forever-agent/index.js
Module not found: Error: Can't resolve 'tls' in 'C:\Users\gdemay\Documents\Mobile-Hybrid2\node_modules\forever-agent'
ERROR in ./node_modules/gaxios/node_modules/https-proxy-agent/index.js
Module not found: Error: Can't resolve 'tls' in 'C:\Users\gdemay\Documents\Mobile-Hybrid2\node_modules\gaxios\node_modules\https-proxy-agent'
ERROR in ./node_modules/http-proxy-agent/index.js
Module not found: Error: Can't resolve 'tls' in 'C:\Users\gdemay\Documents\Mobile-Hybrid2\node_modules\http-proxy-agent'
ERROR in ./node_modules/teeny-request/node_modules/https-proxy-agent/index.js
Module not found: Error: Can't resolve 'tls' in 'C:\Users\gdemay\Documents\Mobile-Hybrid2\node_modules\teeny-request\node_modules\https-proxy-agent'
ERROR in ./node_modules/tunnel-agent/index.js
Module not found: Error: Can't resolve 'tls' in 'C:\Users\gdemay\Documents\Mobile-Hybrid2\node_modules\tunnel-agent'
i 「wdm」: Failed to compile.

    ERROR in src/app/services/google-speech-to-text.service.ts(22,27): error TS2339: Property 'readFileSync' does not exist on type 'typeof File'.


4

2 に答える 2