test_routepoint90_media.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/usr/bin/env python3
  2. import asyncio
  3. import json
  4. import sys
  5. from app.config import Settings
  6. from app.media import ThreeCXMediaClient
  7. from app.media_session import MediaSession
  8. from app.whisper import WhisperWorker
  9. async def main():
  10. settings = Settings()
  11. media = ThreeCXMediaClient(settings)
  12. print("=== ROUTEPOINT 90 MEDIA TEST ===")
  13. print("RoutePoint:", settings.threecx_media_routepoint_dn)
  14. print()
  15. print("Suche aktiven Participant ...")
  16. participants = await media.participants()
  17. print("Participants:", len(participants))
  18. if not participants:
  19. print()
  20. print("KEIN AKTIVER PARTICIPANT.")
  21. print("Jetzt DN 90 anrufen und den Anruf annehmen.")
  22. return 2
  23. print(json.dumps(
  24. participants,
  25. indent=2,
  26. ensure_ascii=False,
  27. ))
  28. connected = [
  29. p for p in participants
  30. if str(p.get("status", "")).lower() == "connected"
  31. ]
  32. if not connected:
  33. print()
  34. print("Kein CONNECTED Participant gefunden.")
  35. return 3
  36. participant = connected[0]
  37. print()
  38. print("=== VERWENDE PARTICIPANT ===")
  39. print("ID:", participant.get("id"))
  40. print("Call-ID:", participant.get("callid"))
  41. print("Leg-ID:", participant.get("legid"))
  42. print("Status:", participant.get("status"))
  43. print()
  44. whisper = WhisperWorker(settings)
  45. session = MediaSession(
  46. settings,
  47. media,
  48. whisper,
  49. )
  50. print("Starte MediaSession ...")
  51. print("Jetzt ca. 10 Sekunden sprechen.")
  52. print()
  53. result = await session.process_participant(
  54. participant,
  55. max_bytes=160000,
  56. )
  57. print()
  58. print("=== MEDIA ERGEBNIS ===")
  59. print("Call-ID:", result["callid"])
  60. print("Leg-ID:", result["legid"])
  61. print("Participant:", result["participant_id"])
  62. print("Audio:", result["audio_bytes"], "Bytes")
  63. print("WAV:", result["audio_file"])
  64. print()
  65. transcription = result["transcription"]
  66. print("=== WHISPER ===")
  67. print("Sprache:", transcription["language"])
  68. print(
  69. "Wahrscheinlichkeit:",
  70. transcription["language_probability"],
  71. )
  72. print("Text:", transcription["text"])
  73. print()
  74. print("Segmente:", len(transcription["segments"]))
  75. return 0
  76. if __name__ == "__main__":
  77. sys.exit(asyncio.run(main()))