Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

GCP Speech to text mix language( Chinese and English) translation

Hello, I want to make services it can transcribe speech (Chinese and English) into text (English) in 1 audio file. Here the code and API for calling the services.

def transcribe_audio(file_path😞
    # Initialize the Speech-to-Text client
    speech_client = speech.SpeechClient()

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

    audio = speech.RecognitionAudio(content=content)
    config = speech.RecognitionConfig(
        encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,  # Change as necessary
        sample_rate_hertz=48000,  # Change as necessary
        language_code="zh-TW",  # Chinese language code
        alternative_language_codes=["en-US"],
        enable_automatic_punctuation=True,
    )

    # Transcribe audio
    response = speech_client.recognize(config=config, audio=audio)

    # Extract the transcript
    transcript = ""
    for result in response.results:
        transcript += result.alternatives[0].transcript + " "

    print(f'Transcript in Chinese: {transcript.strip()}')

    # Now translate the transcript to English
    translate_client = translate.Client()
    translation = translate_client.translate(transcript, target_language='en')

    print(f'Translated Transcript in English: {translation["translatedText"]}')
transcribe_audio("D:/data.wav"
 
but the transcribe and translate it messy. does the GCP support mix language? I see the language it only support 1 language. Thanks a lot.
Solved Solved
0 1 1,167
1 ACCEPTED SOLUTION

Hi @zhongshun,

Welcome to Google Cloud Community!

You are correct that Google Cloud Speech-to-Text does not support transcribing audio with mixed-language content. Alternatively, you might consider submitting a feature request for mixed language inputs in Speech-to-Text. While I can’t provide a timeline for when this enhancement might be available, I recommend keeping an eye on the issue tracker and checking the release notes for the latest updates.

I hope the above information is helpful.

View solution in original post

1 REPLY 1

Hi @zhongshun,

Welcome to Google Cloud Community!

You are correct that Google Cloud Speech-to-Text does not support transcribing audio with mixed-language content. Alternatively, you might consider submitting a feature request for mixed language inputs in Speech-to-Text. While I can’t provide a timeline for when this enhancement might be available, I recommend keeping an eye on the issue tracker and checking the release notes for the latest updates.

I hope the above information is helpful.