Speech-to-Text dengan tanda baca dan emoji lisan

Contoh ini menunjukkan cara menggunakan Speech-to-Text API untuk mentranskripsikan audio dengan emoji dan tanda baca lisan.

Contoh kode

Python

Untuk mempelajari cara menginstal dan menggunakan library klien untuk Cloud STT, lihat Library klien Cloud STT. Untuk mengetahui informasi selengkapnya, baca Dokumentasi referensi API Python Cloud STT.

Untuk melakukan autentikasi ke Cloud STT, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

from google.cloud import speech_v1p1beta1 as speech
from google.protobuf import wrappers_pb2

client = speech.SpeechClient()

speech_file = "resources/commercial_mono.wav"

with open(speech_file, "rb") as audio_file:
    content = audio_file.read()

audio = speech.RecognitionAudio(content=content)
config = speech.RecognitionConfig(
    encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,
    sample_rate_hertz=8000,
    language_code="en-US",
    # Enable spoken punctuation
    enable_spoken_punctuation=wrappers_pb2.BoolValue(value=True),
    # Enable spoken emojis
    enable_spoken_emojis=wrappers_pb2.BoolValue(value=True),
)

response = client.recognize(config=config, audio=audio)

for i, result in enumerate(response.results):
    alternative = result.alternatives[0]
    print("-" * 20)
    print(f"First alternative of result {i}")
    print(f"Transcript: {alternative.transcript}")

return response.results

Langkah berikutnya

Untuk menelusuri dan memfilter contoh kode untuk produk Google Cloud lainnya, lihat browser contohGoogle Cloud .