Evan Liu | 4528959 | 2024-03-21 17:46:12 | [diff] [blame^] | 1 | // Copyright 2024 The Chromium Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "components/soda/soda_util.h" |
| 6 | |
| 7 | #include "base/cpu.h" |
| 8 | #include "base/feature_list.h" |
| 9 | #include "build/build_config.h" |
| 10 | |
| 11 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
| 12 | #include "ash/constants/ash_features.h" |
| 13 | #endif |
| 14 | |
| 15 | #if BUILDFLAG(IS_CHROMEOS_LACROS) |
| 16 | #include "chromeos/startup/browser_params_proxy.h" |
| 17 | #endif |
| 18 | |
| 19 | #if BUILDFLAG(IS_WIN) |
| 20 | #include "base/win/windows_version.h" |
| 21 | #endif |
| 22 | |
| 23 | namespace speech { |
| 24 | |
| 25 | bool IsOnDeviceSpeechRecognitionSupported() { |
| 26 | // Some Chrome OS devices do not support on-device speech. |
| 27 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
| 28 | if (!base::FeatureList::IsEnabled( |
| 29 | ash::features::kOnDeviceSpeechRecognition)) { |
| 30 | return false; |
| 31 | } |
| 32 | #elif BUILDFLAG(IS_CHROMEOS_LACROS) |
| 33 | if (!chromeos::BrowserParamsProxy::Get()->IsOndeviceSpeechSupported()) { |
| 34 | return false; |
| 35 | } |
| 36 | #endif |
| 37 | |
| 38 | #if BUILDFLAG(IS_LINUX) |
| 39 | // Check if the CPU has the required instruction set to run the Speech |
| 40 | // On-Device API (SODA) library. |
| 41 | static bool has_sse41 = base::CPU().has_sse41(); |
| 42 | if (!has_sse41) { |
| 43 | return false; |
| 44 | } |
| 45 | #endif |
| 46 | |
| 47 | #if BUILDFLAG(IS_WIN) && defined(ARCH_CPU_ARM64) |
| 48 | // The Speech On-Device API (SODA) component does not support Windows on |
| 49 | // arm64. |
| 50 | return false; |
| 51 | #else |
| 52 | return true; |
| 53 | #endif |
| 54 | } |
| 55 | |
| 56 | } // namespace speech |