我有一个 Python 脚本,使用 Speech_recognition 包来识别语音并返回所说内容的文本。然而,转录有几秒钟的延迟。是否有另一种方法可以编写此脚本以在说出每个单词时返回它?我有另一个脚本来执行此操作,使用 pysphinx 包,但结果非常不准确。
安装依赖:
pip install SpeechRecognition
pip install pocketsphinx
Run Code Online (Sandbox Code Playgroud)
脚本 1 - 延迟语音到文本:
import speech_recognition as sr
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Please wait. Calibrating microphone...")
# listen for 5 seconds and create the ambient noise energy level
r.adjust_for_ambient_noise(source, duration=5)
print("Say something!")
audio = r.listen(source)
# recognize speech using Sphinx
try:
print("Sphinx thinks you said '" + r.recognize_sphinx(audio) + "'")
except sr.UnknownValueError:
print("Sphinx could not understand audio") …Run Code Online (Sandbox Code Playgroud) python speech-recognition speech-to-text cmusphinx pocketsphinx
我想为我的Reticulate包设置Python的默认发行版.我用,
Sys.setenv(RETICULATE_PYTHON = "/usr/local/bin/python3")
Run Code Online (Sandbox Code Playgroud)
但是,每次启动时我都必须重新输入这行代码.如何永久地设置这个代码,所以我不需要每次都指定我需要哪个Python发行版?
我有Font Awesome的专业版,它使我可以访问浅色图标。我正在通过 CSS创建图标(例如:地址簿图标),如下所示:
.icon-link::before { content: "\f2bb" }
Run Code Online (Sandbox Code Playgroud)
但是,这仅呈现图标的正常版本,而不是浅色版本。我该怎么做才能完全使用 CSS(甚至 Javascript/JQuery)而不是 HTML来呈现图标的浅色版本?
我对深入研究 HTML 并将(font awesome light)类添加到每个适用对象或父对象或其他任何东西的常见解决方案不感兴趣.fal。
我有一个嵌套列表,如下所示:
> ex <- list(list(c("This", "is", "an", "example", "."), c("I", "really", "hate", "examples", ".")), list(c("How", "do", "you", "feel", "about", "examples", "?")))
> ex
[[1]]
[[1]][[1]]
[1] "This" "is" "an" "example" "."
[[1]][[2]]
[1] "I" "really" "hate" "examples" "."
[[2]]
[[2]][[1]]
[1] "How" "do" "you" "feel" "about" "examples" "?"
Run Code Online (Sandbox Code Playgroud)
我想把它转换成像这样的元素:
> tibble(d_id = as.integer(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2)),
+ s_id = as.integer(c(1, 1, 1, 1, 1, 2, 2, 2, …Run Code Online (Sandbox Code Playgroud) 我是一名试图进入 Python 的 R 程序员。在 R 中,当我想有条件地改变一列时,我使用:
col = dplyr::mutate(col, ifelse(condition, if_true(x), if_false(x))
Run Code Online (Sandbox Code Playgroud)
在 Python 中,如何有条件地改变列值?这是我的最小可重复示例:
def act(cntnt):
def do_thing(cntnt):
return(cntnt + "has it")
def do_other_thing(cntnt):
return(cntnt + "nope")
has_abc = cntnt.str.contains.contains("abc")
if has_abc == T:
cntnt[has_abc].apply(do_thing)
else:
cntnt[has_abc].apply(do_other_thing)
Run Code Online (Sandbox Code Playgroud) 我有一个由具有特定地理坐标(纬度和经度)的多个数据点组成的数据框。我正在创建一个等值区域样式的世界地图,其中地理区域根据落在该区域边界内的数据点数量进行着色。
有没有一种简单的方法来完成我在 R 中尝试做的事情,最好使用“maps”包的世界地图和“ggplot2”地图绘制函数?
这是我所拥有的最低限度可重现的结果:
library(ggplot2)
library(maps)
data <- data.frame(lat = 40.730610, lon = -73.935242)
ggplot() +
geom_polygon(data = map_data("world"), aes(x = long, y = lat, group = group, fill = group)) +
coord_fixed(1.3)
Run Code Online (Sandbox Code Playgroud)
我注意到fill绘图项函数上的参数可用于创建分区统计图效果。在这里,函数的fill参数用于创建分区统计图,其中每个组的颜色编码不同。aes()geom_polygon()
基本上,我正在寻找一个正则表达式来选择所有标点符号,除了URL内的标点符号.
本质上,如果我有字符串:
This is a URL: https://test.com/ThisIsAURL !
Run Code Online (Sandbox Code Playgroud)
并删除它应该成为的所有匹配:
This is a URL https://test.com/ThisIsAURL
Run Code Online (Sandbox Code Playgroud)
gsub("[[:punct:]]", "", x)删除所有标点符号,包括URL.我尝试使用负面外观来选择https后使用的标点符号,但这是不成功的.
在我需要的情况下,所有URL都是Twitter链接式URL https://t.co/.他们没有结束.com.他们也没有一个以上的背斜塞(/ThisIsAURL).但是,理想的是,我希望正则表达式尽可能多样化,能够在任何URL上成功执行此操作.
r ×4
python ×2
choropleth ×1
cmusphinx ×1
conditional ×1
css ×1
dplyr ×1
font-awesome ×1
fonts ×1
ggplot2 ×1
gis ×1
if-statement ×1
magrittr ×1
pandas ×1
pocketsphinx ×1
regex ×1
text-mining ×1