You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 1 година
преди 1 година
преди 1 година
преди 1 година
преди 1 година
преди 1 година
преди 1 година
преди 1 година
преди 1 година
123456789101112131415161718192021222324252627282930
  1. """
  2. google voice service
  3. """
  4. import json
  5. import openai
  6. from bridge.reply import Reply, ReplyType
  7. from config import conf
  8. from common.log import logger
  9. from voice.voice import Voice
  10. class OpenaiVoice(Voice):
  11. def __init__(self):
  12. openai.api_key = conf().get('open_ai_api_key')
  13. def voiceToText(self, voice_file):
  14. logger.debug(
  15. '[Openai] voice file name={}'.format(voice_file))
  16. try:
  17. file = open(voice_file, "rb")
  18. result = openai.Audio.transcribe("whisper-1", file)
  19. text = result["text"]
  20. reply = Reply(ReplyType.TEXT, text)
  21. logger.info(
  22. '[Openai] voiceToText text={} voice file name={}'.format(text, voice_file))
  23. except Exception as e:
  24. reply = Reply(ReplyType.ERROR, str(e))
  25. finally:
  26. return reply