将文本转换为语音录制,然后在扑打电话号码后播放它

发布于 2025-02-01 14:16:28 字数 302 浏览 3 评论 0原文

我正在尝试制作一个获取用户位置的应用程序,然后致电一个号码(由用户预先选择)发送录制的语音消息,例如Say “位置为{atturitue}度,{latitude}学位”,但是我找不到任何可以做的事情,我在某些搜索时发现了Twilio,但是在flutter package twilio_voice中,我找不到任何可以做我想做的事情。

所以我的问题是可以在Twilio中完成,如果不是,我该怎么办?

(编辑:我已经找出了获取用户位置的零件,只需在屏幕上显示它,剩下的部分就是将其转换为语音并在呼叫上播放)

I'm trying to make an app which gets the location of a user and then call a number(pre-selected by user) to send a recorded voice message, like say "Location is {longitude} degrees, {latitude} degrees" but I can't find anything to do the same I found Twilio on some searching but in the Flutter package twilio_voice I can't find anything to do what I want.

So my question is can this be done in Twilio and if not what else I can do?

(Edit :I have figured out the part to fetch the user location and just display it on the screen, the part that remains is to convert this to speech and play on call)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

过气美图社 2025-02-08 14:16:28

您可以使用Twilio实现这一目标,但是您需要一台服务器来向Twilio API提出请求。要向Twilio拨打API,您需要使用您的帐户SID和Auth Token,如果您要嵌入flutter应用程序中的api,那么恶意用户将能够对您的应用程序进行反复编译,窃取您的凭据并滥用您的帐户。

因此,最好的方法是构建一个可以代表应用程序进行API调用的服务器端应用程序,然后将相关数据(在这种情况下为位置)从您的移动应用程序发送到服务器应用程序。

在服务器端应用程序上,一旦收到位置数据,您就可以通过在 twilio调用资源并传递要调用的号码,您正在调用的号码以及您要在呼叫上执行的Twiml。 twiml告诉twilio twilio在呼叫中,在这种情况下,您可以指导twilio to

我看到您过去曾问过Python问题,所以这里是一个呼叫Twilio api以创建python python call python :::::::::::::::

import os
from twilio.rest import Client

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)

call = client.calls.create(
                        twiml='<Response><Say>Location is {longitude} degrees, {latitude} degrees</Say></Response>',
                        to=TO_NUMBER,
                        from_=YOUR_TWILIO_NUMBER
                    )

print(call.sid)

You can achieve this with Twilio, however you will need a server from which to make the requests to the Twilio API. To make an API call to Twilio you need to use your Account SID and Auth Token and if you were to embed those within your Flutter application then a malicious user would be able to decompile your app, steal your credentials and abuse your account.

So, the best way is to build a server-side application that can make the API calls on behalf of your app and then send the relevant data (the location, in this case) from your mobile app to the server application.

On the server-side application, once you receive the location data you can generate a call by calling on the Twilio calls resource and pass the number you want to call, the number you are calling from and the TwiML you want to execute on the call. TwiML tells Twilio what to do on a call, and in this case you can direct Twilio to <Say> the message with the location.

I see you've asked python questions in the past, so here's a quick example of calling the Twilio API to create a call in python:

import os
from twilio.rest import Client

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)

call = client.calls.create(
                        twiml='<Response><Say>Location is {longitude} degrees, {latitude} degrees</Say></Response>',
                        to=TO_NUMBER,
                        from_=YOUR_TWILIO_NUMBER
                    )

print(call.sid)
深居我梦 2025-02-08 14:16:28

您需要将问题划分为较小的子问题,并测试本机OS(Android / ios)是否允许您:

  1. 获取当前用户位置,
  2. 创建一个带有文本的音频语音生成器
  3. 研究的音频文件,如果可以编程呼叫(这可能很棘手)
  4. 进行电话研究
  5. 如果可以在通话中播放音频文件,

You need to divide your problem into smaller subproblems and test if the native OS (Android / iOS) allows you this:

  1. Fetching current user location
  2. Create an audio file with a text-to-audio speech generator
  3. Research if it's possible to make calls programmatically (this might be tricky)
  4. Make a phone call
  5. Research if it's possible to play audio file while in call
  6. Play an audio file on speaker while incall
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文