{"id":3890,"date":"2023-10-31T13:36:19","date_gmt":"2023-10-31T04:36:19","guid":{"rendered":"https:\/\/blog.since2020.jp\/?p=3890"},"modified":"2023-10-31T13:36:19","modified_gmt":"2023-10-31T04:36:19","slug":"whisper-api","status":"publish","type":"post","link":"https:\/\/since2020.jp\/media\/whisper-api\/","title":{"rendered":"\u521d\u5fc3\u8005\u3067\u3082\u5206\u304b\u308b\uff01Whisper API\u306e\u4f7f\u3044\u65b9\u30ac\u30a4\u30c9"},"content":{"rendered":"\n<p>Whisper API\u306e\u4f7f\u3044\u65b9\u3092\u521d\u5fc3\u8005\u306b\u3082\u308f\u304b\u308a\u3084\u3059\u304f\u8aac\u660e\u3057\u307e\u3057\u305f\uff01<\/p>\n\n\n<h2>\u306f\u3058\u3081\u306b<\/h2>\n<p><span><span data-token-index=\"0\" class=\"discussion-level-1 discussion-id-bd3301b8-eda7-4ae2-9a63-bfcb4ea7a890 notion-enable-hover\">OpenAI<\/span>\u306eWhisper API\u3068ChatGPT API\u3092\u4f7f\u3063\u3066\u307f\u305f\u306e\u3067\u3001\u305d\u306e\u6982\u8981\u3092\u7d39\u4ecb\u3057\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/span><!-- notionvc: ada14a9b-e71b-494b-980c-bf39049e9e3b --><\/p>\n\n<h2>whisper \u306b\u3064\u3044\u3066<\/h2>\n<p>Whisper\u3068\u306f\u97f3\u58f0\u30c7\u30fc\u30bf\u3092\u30c6\u30ad\u30b9\u30c8\u30c7\u30fc\u30bf\u306b\u5909\u63db\u3059\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3042\u308a\u3001github\u4e0a\u3067\u305d\u306e\u30e2\u30c7\u30eb\u304c\u516c\u958b\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\r\n<p><span data-token-index=\"1\" class=\"discussion-level-1 discussion-id-751d9a23-9234-4b26-ab65-877e5a030a7b notion-enable-hover\">\u3057\u304b\u3057\u3001CPU\u3092\u4f7f\u3063\u3066<\/span>\u97f3\u58f0\u30c7\u30fc\u30bf\u304b\u3089\u30c6\u30ad\u30b9\u30c8\u30c7\u30fc\u30bf\u306e\u5909\u63db\u3059\u308b\u3068\u6642\u9593\u304c\u304b\u304b\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001\u6027\u80fd\u304c\u6700\u3082\u9ad8\u3044Large\u30e2\u30c7\u30eb\u3067mp3\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001\u97f3\u58f0\u30c7\u30fc\u30bf\u306e\u9577\u3055\u306e\u7d042\u500d\u306e\u5b9f\u884c\u6642\u9593\u304c\u304b\u304b\u3063\u3066\u3057\u307e\u3044\u307e\u3059<span data-token-index=\"3\" class=\"discussion-level-1 discussion-id-751d9a23-9234-4b26-ab65-877e5a030a7b notion-enable-hover\">\u3002<\/span>\u305d\u3053\u3067\u3001\u4eca\u56de\u306fGPU\u3092\u7528\u610f\u3059\u308b\u3053\u3068\u306a\u304f\u3001$0.006\/min\u3068\u3044\u3046\u5b89\u4fa1\u3067\u5b9f\u884c\u3067\u304d\u308b\u3068\u3044\u3046\u3053\u3068\u3067API\u3092\u4f7f\u7528\u3057\u307e\u3057\u305f\u3002<!-- notionvc: 69b5cd76-64a3-4a34-81c4-ed8060f9b80c --><\/p>\n\n<h2>\u6e96\u5099<\/h2>\n<p>\u5404\u7a2e\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30a4\u30f3\u30dd\u30fc\u30c8\u3068\u4f7f\u7528\u3059\u308b\u97f3\u58f0\u30d5\u30a1\u30a4\u30eb\u306e\u51e6\u7406\u3092\u884c\u3044\u307e\u3059\u3002Whisper API\u306fOpenAI\u306eAPI\u30ad\u30fc\u304c\u5fc5\u8981\u306b\u306a\u308b\u306e\u3067&#8221;Your API key&#8221;\u3092\u7f6e\u304d\u63db\u3048\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\r\n<p>Whisper API\u306b\u5165\u529b\u3067\u304d\u308b\u97f3\u58f0\u30c7\u30fc\u30bf\u306e\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u306e\u4e0a\u9650\u304c25MB\u306a\u306e\u3067\u3001\u9577\u3044\u97f3\u58f0\u30c7\u30fc\u30bf\u3067\u306f\u5206\u5272\u304c\u5fc5\u8981\u3068\u306a\u308a\u307e\u3059\u3002\u3053\u3053\u3067\u306f20\u5206\u306e\u30bb\u30b0\u30e1\u30f3\u30c8\u306b\u5206\u3051\u3066\u5b9f\u884c\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\r\n<p><!-- notionvc: 359a7057-a311-4c2f-8f47-5bdf31f5a18e --><\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>import openai\r\nfrom pydub import AudioSegment\r\nopenai.api_key = \"Your API key\"\r\n\r\nsound_file = AudioSegment.from_file(input_folder_path)\r\nsound_length = duration = sound_file.duration_seconds\r\nprint(f\"length: {sound_length}\\n\")\r\ntime_segment_length = 20 * 60 * 1000\r\n\r\ncurrent_time_index = 0\r\nwhile current_time_index * time_segment_length &lt; sound_length * 1000:\r\ndata_segment = sound_file[current_time_index*time_segment_length:(current_time_index+1)*time_segment_length]\r\ntmp_file_path = os.path.join(adjusted_audio_folder_path, filename.replace(extension, f\"_{current_time_index}.mp3\"))\r\ndata_segment.export(tmp_file_path, format=\"mp3\")\r\nprint(f\"{current_time_index}th data was exported.\\n\")\r\ncurrent_time_index += 1<\/code><\/pre>\r\n<\/div>\n\n<h2>Whisper API\u306b\u3088\u308b\u97f3\u58f0\u304b\u3089\u30c6\u30ad\u30b9\u30c8\u3078\u306e\u5909\u63db<\/h2>\n<p>API\u3067whisper\u3092\u4f7f\u3046\u5834\u5408\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306bopenai.Audio.transcribe\u95a2\u6570\u3092\u5b9f\u884c\u3059\u308b\u3060\u3051\u3067\u3059\u3002\u3053\u306e\u305f\u3081\u5b9f\u88c5\u306f\u6975\u3081\u3066\u7c21\u5358\u3067\u3059\u304c\u3001\u305d\u308c\u3068<span data-token-index=\"1\" class=\"discussion-level-1 discussion-id-84a4d9de-d619-4f86-969a-a84194513e2c notion-enable-hover\">\u540c\u6642\u306b\u3001<\/span>\u81ea\u5206\u3067\u8abf\u6574\u3067\u304d\u308b\u30d1\u30e9\u30e1\u30fc\u30bf\u306f\u3042\u307e\u308a\u591a\u304f\u3042\u308a\u307e\u305b\u3093\u3002<!-- notionvc: 5ba25e9a-c64d-4290-8578-5afa87499e41 --><\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>with open(current_file, \"rb\") as f:\r\ntranscript = openai.Audio.transcribe(\r\nfile=f,\r\nmodel=\"whisper-1\",\r\nlanguage=\"ja\",\r\nresponse_format=\"verbose_json\",\r\nprompt = \"\u3053\u306e\u97f3\u58f0\u3067\u306f3\u4eba\u306e\u4eba\u304c\u8a71\u3092\u3057\u3066\u3044\u307e\u3059\u3002\u305d\u306e\u9332\u753b\u306e\u97f3\u58f0\u30c7\u30fc\u30bf\u3067\u3059\u3002\"\r\n)<\/code><\/pre>\r\n<\/div>\r\n<p>\u3053\u306e\u95a2\u6570\u306e\u4e2d\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u5f15\u6570\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\r\n<p style=\"padding-left: 40px\">1. file (\u5fc5\u9808): \u30c6\u30ad\u30b9\u30c8\u306b\u5909\u63db\u3059\u308b\u97f3\u58f0\u306e\u30d5\u30a1\u30a4\u30eb<\/p>\r\n<p style=\"padding-left: 40px\">2.model (\u5fc5\u9808): \u73fe\u5728(2023\/10)\u306fwhisper-1\u306e\u307f<\/p>\r\n<p style=\"padding-left: 40px\">3.language: \u5165\u529b\u97f3\u58f0\u306e\u8a00\u8a9e\u3002ISO-639-1\u5f62\u5f0f\u3067\u6307\u5b9a<\/p>\r\n<p style=\"padding-left: 40px\">4.response_format: \u3069\u306e\u3088\u3046\u306a\u5f62\u3067\u51fa\u529b\u3092\u884c\u3046\u304b\u3002verbose_json\u3067\u6642\u9593\u7b49\u5168\u30c7\u30fc\u30bf\u3092\u51fa\u529b<\/p>\r\n<p style=\"padding-left: 40px\">5.temperature: 0\u304b\u30891\u306e\u5024\u3067\u5c0f\u3055\u3044\u307b\u3069\u6c7a\u5b9a\u8ad6\u7684<\/p>\r\n<p style=\"padding-left: 40px\">6.prompt: \u6700\u521d\u306e1\u30bb\u30b0\u30e1\u30f3\u30c8\u306e\u90e8\u5206\u306b\u4e0e\u3048\u308b\u51fa\u529b\u306e\u30d2\u30f3\u30c8<\/p>\r\n<p>\u8cea\u554f\u306b\u5bfe\u3057\u3066\u6b63\u78ba\u306a\u7b54\u3048\u3092\u8fd4\u3059\u3068\u3044\u3046\u524d\u63d0\u306e\u3082\u3068\u3067\u306f5\u306f\u5909\u3048\u305a\u3001\u6027\u80fd\u5411\u4e0a\u306b\u5927\u304d\u304f\u5bc4\u4e0e\u3059\u308b\u306e\u306f6\u306b\u306a\u308a\u307e\u3059\u3002\u3053<span data-token-index=\"1\" class=\"discussion-level-1 discussion-id-7f7c197f-15c6-47fb-a591-1c532aa436a3 notion-enable-hover\">\u3053\u3067\u306fprompt\u3068\u3044\u3046\u5f15\u6570\u3067\u4e0e\u3048\u3066\u3044\u308b\u6587\u7ae0\u3067\u53e5\u8aad\u70b9\u306e\u4f7f\u3044\u65b9\u3092\u524d\u63d0\u77e5\u8b58\u3068\u3057\u3066\u5165\u308c\u308b\u3068\u3044\u3046\u64cd\u4f5c<\/span>\u3092\u884c\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\r\n<p>\u4eca\u56de\u306e\u3088\u3046\u306b\u53e5\u8aad\u70b9\u306e\u4f7f\u3044\u65b9\u3092\u4e0e\u3048\u308b\u3060\u3051\u3067\u3042\u308c\u3070\u3001\u53e5\u8aad\u70b9\u306e\u4f7f\u3044\u65b9\u304c\u308f\u304b\u308b\u3088\u3046\u306a\u6587\u7ae0\u3067\u3042\u308c\u3070\u306a\u3093\u3067\u3082\u69cb\u3044\u307e\u305b\u3093\u3002\u5b9f\u969b\u306e\u7d50\u679c\u304c\u4e0b\u8a18\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\r\n<p>\u53e5\u8aad\u70b9\u304c\u660e\u78ba\u306a\u5f62\u3067\u51fa\u3066\u304f\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002\u3053\u306e\u4ed6\u306b\u3082\u4f7f\u7528\u3059\u308b\u56fa\u6709\u540d\u8a5e\u7b49\u3092prompt\u306e\u4e2d\u3067\u4e0e\u3048\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u3001whisper\u304c\u305d\u306e\u56fa\u6709\u540d\u8a5e\u3092\u8a8d\u8b58\u3055\u305b\u308b\u3068\u3044\u3063\u305f\u4f7f\u3044\u65b9\u3082\u3067\u304d\u308b\u306e\u3067\u8272\u3005\u8a66\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\r\n<p><!-- notionvc: 610e4c02-d17a-46c7-8bad-b1c3969244e9 --><\/p>","protected":false},"excerpt":{"rendered":"<p>Whisper API\u306e\u4f7f\u3044\u65b9\u3092\u521d\u5fc3\u8005\u306b\u3082\u308f\u304b\u308a\u3084\u3059\u304f\u8aac\u660e\u3057\u307e\u3057\u305f\uff01 \u306f\u3058\u3081\u306b OpenAI\u306eWhisper API\u3068ChatGPT API\u3092\u4f7f\u3063\u3066\u307f\u305f\u306e\u3067\u3001\u305d\u306e\u6982\u8981\u3092\u7d39\u4ecb\u3057\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002 whisper \u306b\u3064\u3044\u3066 W [&hellip;]<\/p>\n","protected":false},"author":26,"featured_media":3901,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"content-type":"","swell_btn_cv_data":"","footnotes":"","_wp_rev_ctl_limit":""},"categories":[1249],"tags":[96,145,331],"class_list":["post-3890","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-knowledge","tag-ai","tag-api","tag-python"],"_links":{"self":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts\/3890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/users\/26"}],"replies":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/comments?post=3890"}],"version-history":[{"count":1,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts\/3890\/revisions"}],"predecessor-version":[{"id":3903,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts\/3890\/revisions\/3903"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/media\/3901"}],"wp:attachment":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/media?parent=3890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/categories?post=3890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/tags?post=3890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}