我想实现客户端库Google Cloud,但没有Ionic实现。
如何在Ionic上实现客户端库,以便使用Google Speech To Text?
目前,我试图实现NodeJS客户端库,但有一些问题,因为论坛上的一些人说我们必须使用Ionic的文件原生实现。使用文件为我生成错误。
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'.发布于 2019-11-27 01:00:48
我的理解是不幸的是你不能。NodeJS中的speech to text接口采用了后台技术。
您需要使用Obvi在API上创建一个包装器。
我决定进一步尝试,通过创建一个web套接字服务器,然后将音频从AudioContext传输到web套接字服务器,然后使用google Cloud Speech to Text API客户端库,我可以将音频流式传输到谷歌,并将临时响应返回给浏览器。
发布于 2020-01-29 22:30:47
部分对我起作用的解决方案是使用/node_modules/google_gax/build/src/operationsClient.js,在内部,我重命名为
const configData = require('./operations_client_config');至
const configData = require('./operations_client_config.json');希望这能帮助到别人。
编辑:
如果有人使用了webpack,并且遇到了这个问题,去webpack.config.js添加:
resolve: { extensions: [ '.json' ] }
https://stackoverflow.com/questions/59049091
复制相似问题