Skip to content

Instantly share code, notes, and snippets.

@shehbajdhillon
Last active March 30, 2024 14:37
Show Gist options
  • Select an option

  • Save shehbajdhillon/ef4791db290fcf716d0aeefc8287bebc to your computer and use it in GitHub Desktop.

Select an option

Save shehbajdhillon/ef4791db290fcf716d0aeefc8287bebc to your computer and use it in GitHub Desktop.
Translate transcribed text using GPT
# Previous Code (Unchanged)
def translate_segment(input_text, input_language):
systemMessage = '''
You are an expert translator that can translate texts to and from different languages.
You will translate the input text and will only output the translation
'''
userMessage = f'''
Translate the following text to colloquial {input_language}: {input_text}
'''
completion = openai.ChatCompletion.create(
model="gpt-4",
messages=[
{ "role": "system", "content": systemMessage },
{ "role": "user", "content": userMessage }
]
)
return completion.choices[0].message.content
def main():
file_path, input_language = sys.argv[1:]
input_language = str(input_language).lower()
transcript = transcribe_audio(file_path=file_path)
segments = transcript.segments
for segment in segments:
print("Original Text:", segment.text)
print("Translated Text:", translate_segment(segment.text, input_language))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment