第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

GCP 語(yǔ)音轉(zhuǎn)文本 - Java API 不工作

GCP 語(yǔ)音轉(zhuǎn)文本 - Java API 不工作

桃花長(zhǎng)相依 2023-06-04 17:35:20
我在 Chrome 瀏覽器中使用 MediaRecorder 錄制了一個(gè)示例 .webm 文件。當(dāng)我使用 Google 語(yǔ)音 java 客戶端獲取視頻的轉(zhuǎn)錄時(shí),它返回空轉(zhuǎn)錄。這是我的代碼的樣子SpeechSettings settings = null;Path path = Paths.get("D:\\scrap\\gcp_test.webm");byte[] content = null;try {    content = Files.readAllBytes(path);    settings = SpeechSettings.newBuilder().setCredentialsProvider(credentialsProvider).build();} catch (IOException e1) {    throw new IllegalStateException(e1);}try (SpeechClient speech = SpeechClient.create(settings)) {    // Builds the request for remote FLAC file    RecognitionConfig config = RecognitionConfig.newBuilder()                    .setEncoding(AudioEncoding.LINEAR16)                    .setLanguageCode("en-US")                    .setUseEnhanced(true)                    .setModel("video")                    .setEnableAutomaticPunctuation(true)                    .setSampleRateHertz(48000)                    .build();    RecognitionAudio audio = RecognitionAudio.newBuilder().setContent(ByteString.copyFrom(content)).build();    // RecognitionAudio audio = RecognitionAudio.newBuilder().setUri("gs://xxxx/gcp_test.webm") .build();    // Use blocking call for getting audio transcript    RecognizeResponse response = speech.recognize(config, audio);    List<SpeechRecognitionResult> results = response.getResultsList();    for (SpeechRecognitionResult result : results) {        SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0);        System.out.printf("Transcription: %s%n", alternative.getTranscript());    }} catch (Exception e) {    e.printStackTrace();    System.err.println(e.getMessage());}如果,我使用相同的文件并訪問(wèn)https://cloud.google.com/speech-to-text/并在演示部分上傳文件。它似乎工作正常并顯示轉(zhuǎn)錄。我對(duì)這里出了什么問(wèn)題一無(wú)所知。我驗(yàn)證了演示發(fā)送的請(qǐng)求,這里看起來(lái)像我發(fā)送了一組準(zhǔn)確的參數(shù),但沒(méi)有用。嘗試將文件上傳到云存儲(chǔ),但也給出了相同的結(jié)果(沒(méi)有轉(zhuǎn)錄)。
查看完整描述

2 回答

?
莫回?zé)o

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊

經(jīng)過(guò)錯(cuò)誤和試驗(yàn)(并查看 javascript 示例)后,我可以解決問(wèn)題。音頻的序列化版本應(yīng)為 FLAC 格式。我將視頻文件 (webm) 按原樣發(fā)送到 Google Cloud。該站點(diǎn)上的演示使用 Javascript Audio API 提取音頻流,然后以 base64 格式發(fā)送數(shù)據(jù)以使其工作。

以下是我為獲取輸出而執(zhí)行的步驟。

  1. 使用 FFMPEG 從 webm 中提取音頻流為 FLAC 格式。

    ffmpeg -i sample.webm -vn -acodec flac sample.flac

  2. 提取的文件應(yīng)使用存儲(chǔ)云提供或作為 ByteString 發(fā)送。

  3. 在調(diào)用語(yǔ)音 API 時(shí)設(shè)置適當(dāng)?shù)哪P停ㄓ⒄Z(yǔ)語(yǔ)言video模型有效,法語(yǔ)模型有效command_and_search)。我對(duì)此沒(méi)有任何合乎邏輯的理由。我在谷歌云站點(diǎn)上的演示中反復(fù)試驗(yàn)后意識(shí)到了這一點(diǎn)。


查看完整回答
反對(duì) 回復(fù) 2023-06-04
?
慕的地8271018

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超4個(gè)贊

我得到了 flac 編碼文件的結(jié)果。


示例代碼結(jié)果帶有時(shí)間戳的單詞,


public class SpeechToTextSample {


public static void main(String... args) throws Exception {


?try (SpeechClient speechClient = SpeechClient.create()) {


? ?String gcsUriFlac = "gs://yourfile.flac";


? ?RecognitionConfig config =

? ? ? ?RecognitionConfig.newBuilder()

? ? ? ? ? ?.setEncoding(AudioEncoding.FLAC)??

? ? ? ? ? ?.setEnableWordTimeOffsets(true)

? ? ? ? ? ?.setLanguageCode("en-US")

? ? ? ? ? ?.build();


? ?RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(gcsUriFlac).build(); //for large files

? ?OperationFuture<LongRunningRecognizeResponse, LongRunningRecognizeMetadata> response = speechClient.longRunningRecognizeAsync(config, audio);

? ?while (!response.isDone()) {

? ? ? ? ? System.out.println("Waiting for response...");

? ? ? ? ? Thread.sleep(1000);

? ? ? ? }

? ?// Performs speech recognition on the audio file


? ?List<SpeechRecognitionResult> results = response.get().getResultsList();


? ?for (SpeechRecognitionResult result : results) {

? ? ? SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0);

? ? ?System.out.printf("Transcription: %s%n", alternative.getTranscript());

? ? ?for (WordInfo wordInfo : alternative.getWordsList()) {

? ? ? ? ?System.out.println(wordInfo.getWord());

? ? ? ? ?System.out.printf(

? ? ? ? ? ? ?"\t%s.%s sec - %s.%s sec\n",

? ? ? ? ? ? ?wordInfo.getStartTime().getSeconds(),

? ? ? ? ? ? ?wordInfo.getStartTime().getNanos() / 100000000,

? ? ? ? ? ? ?wordInfo.getEndTime().getSeconds(),

? ? ? ? ? ? ?wordInfo.getEndTime().getNanos() / 100000000);

? ? ? ?}

? ?}

?}

}

}

GCP 支持不同的語(yǔ)言,我在示例中使用了“en-US”。



查看完整回答
反對(duì) 回復(fù) 2023-06-04
  • 2 回答
  • 0 關(guān)注
  • 159 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)