XunFeiVoiceJob.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Jobs;
  3. use App\Events\AuditMediaDeal;
  4. use App\Models\Media\MediaSecure;
  5. use App\Services\Vendor\Miniprogram\Security;
  6. use App\Services\Vendor\Xunfei\Voice2Text;
  7. use Illuminate\Bus\Queueable;
  8. use Illuminate\Queue\SerializesModels;
  9. use Illuminate\Queue\InteractsWithQueue;
  10. use Illuminate\Contracts\Queue\ShouldQueue;
  11. use Illuminate\Foundation\Bus\Dispatchable;
  12. class XunFeiVoiceJob implements ShouldQueue
  13. {
  14. use Dispatchable;
  15. use InteractsWithQueue;
  16. use Queueable;
  17. use SerializesModels;
  18. protected $media;
  19. /**
  20. * Create a new job instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct($media)
  25. {
  26. $this->media = $media;
  27. }
  28. /**
  29. * Execute the job.
  30. *
  31. * @return void
  32. */
  33. public function handle()
  34. {
  35. $media = $this->media;
  36. $taskId = $media->task_id;
  37. $XunFeiService = new Voice2Text();
  38. $data = $XunFeiService->getProgress($taskId);
  39. $data = json_decode($data['data'], true);
  40. if ($data['status'] !== 9) {
  41. $this->release(60);
  42. }
  43. // 讯飞语音转译
  44. $data = $XunFeiService->getResult($taskId);
  45. if ($data['ok'] === 0) {
  46. $result = json_decode($data['data'], true);
  47. $media->machine_result = $result;
  48. $translate = implode('', array_column($result, 'onebest'));
  49. $media->translate = sprintf('【转译结果】%s', $translate);
  50. if (!$translate) {
  51. $media->audit_suggestion = MediaSecure::MACHINE_SUGGESTION_BLOCK;
  52. $media->result = MediaSecure::MANUAL_SUGGESTION_BLOCK;
  53. $media->save();
  54. event(new AuditMediaDeal($media));
  55. return;
  56. } else {
  57. // 文字检测
  58. $security = new Security();
  59. $result = $security->msgSecCheck($translate);
  60. if ($result['errcode']) {
  61. $media->audit_suggestion = MediaSecure::MACHINE_SUGGESTION_BLOCK;
  62. $media->result = MediaSecure::MANUAL_SUGGESTION_BLOCK;
  63. $media->save();
  64. event(new AuditMediaDeal($media));
  65. } else {
  66. $media->audit_suggestion = 1;
  67. $media->save();
  68. }
  69. }
  70. } else {
  71. $media->translate = sprintf('【进行中】%s', $data['failed']);
  72. $media->audit_suggestion = 0;
  73. $media->save();
  74. }
  75. }
  76. }