首页 \ 问答 \ 在通过文本到语音说话然后恢复时暂停手机铃声(Pause Phone Ringtone while Speaking through Text To Speech and then Resume)

在通过文本到语音说话然后恢复时暂停手机铃声(Pause Phone Ringtone while Speaking through Text To Speech and then Resume)

我正在制作一个使用TTS说出来电者姓名的来电者。 我想在TTS讲话时暂停铃声然后恢复铃声。 根据我的研究,我们可以使用AudioFocus (希望如此)。 无论如何,我使用以下代码

更新

我现在正在使用此代码。

public void speak(final String talk) throws InterruptedException {
     final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
     int musicVolume= audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
     audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, musicVolume, 0);
     audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);

    int result = tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {

        @Override
        public void onStart(String utteranceId) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onError(String utteranceId) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onDone(String utteranceId) {
            // TODO Auto-generated method stub
            audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            System.out.println("done");
        }
    });
    HashMap<String, String> params = new HashMap<String, String>();
    params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,"stringId");
    tts.speak(talk, TextToSpeech.QUEUE_FLUSH, params);
    System.out.println("speaking after tts is over" + talk+" "+result);

}

虽然Ringtone已停止并且播放了tts ,但播放ttsRingtone未恢复。 我该怎么办?


I am making a caller speaking application which speak caller name using TTS. I want to pause the ringtone while TTS is speaking then resuming the ringtone. From what i have researched we can use AudioFocus (hope so). Anyway i am using the following code

Update

I am using this code now.

public void speak(final String talk) throws InterruptedException {
     final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
     int musicVolume= audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
     audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, musicVolume, 0);
     audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);

    int result = tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {

        @Override
        public void onStart(String utteranceId) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onError(String utteranceId) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onDone(String utteranceId) {
            // TODO Auto-generated method stub
            audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            System.out.println("done");
        }
    });
    HashMap<String, String> params = new HashMap<String, String>();
    params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,"stringId");
    tts.speak(talk, TextToSpeech.QUEUE_FLUSH, params);
    System.out.println("speaking after tts is over" + talk+" "+result);

}

Although the Ringtone is stopped and tts is played but after tts is played Ringtone is not resumed. What should i do?


原文:https://stackoverflow.com/questions/17890903
更新时间:2024-03-27 06:03

最满意答案

指针类型转换在机器级别上不起任何作用。 内存中的值仍然只是内存中一个普通的旧值。

在语言层面,该值被用作地址。 换句话说,它通常用作传递给需要内存位置的操作的值,例如程序集“加载”操作。

在语言层面,额外的结构被添加到机器操作中,其中一个“额外”是数据类型。 编译器负责检查类型规则是否存在,但运行时不存在这样的约束。

因此,转换在运行时不做任何事情,但是在编译时它会指示编译器不发出错误,因为指针值的类型现在将被视为与持有该地址的变量的兼容类型。


Pointer type casting doesn't do anything at the machine level. The value in memory is still just a plain old value in memory.

At the language level, that value is used as an address. In other words it is often used as the value passed to operations that require memory locations, such as the assembly "load" operation.

At the language level, extra constructs are added to the machine operations, and one of those "extras" are data types. The compiler is responsible for checking if type-rule violations exist, but at run time there is not such a constraint.

As a result, the cast does nothing at run time, but at compile time it directs the compiler to not emit an error as the type of the pointer's value will now be considered a compatible type to the variable holding the address.

相关问答

更多
  • 您没有在disk.h声明construct_generic_attribute() ,因此在看到函数调用时,编译器假定它具有默认签名 - 即int construct_generic_attribute(); 。 感谢您对此进行质疑,而不是盲目地添加演员(这似乎有效!) You did not declare construct_generic_attribute() in disk.h, so upon seeing the function call the compiler assumes it ha ...
  • 我会使用reinterpret_cast,并且总是强制转换为你所投射的相同指针类型,以避免任何转移。 std::ofstream *fs = new std::ofstream("example.txt"); double d = reinterpret_cast(fs); fs = reinterpret_cast(static_cast(d)); 或者先投射到std :: ios: std::ofstream *fs = new ...
  • 假设您的原始代码是正确的,相应的赋值如下所示: *((zend_long*)*ptr) = *(ISC_LONG*)var->sqldata; Assuming that your original code is correct, the corresponding assignment looks like this: *((zend_long*)*ptr) = *(ISC_LONG*)var->sqldata;
  • 这里的问题是下面这行 pList = (TYPE_A*) pList; 仍然分配给void*指针,因此转换是无用的,其余的代码表现得好像它没有发生。 我不知道一个干净的方法来解决这个问题,我很抱歉。 我打算建议一个中间struct但由于你想直接修改实例,因此无法工作。 如果这是C++ ,那么泛型就是答案。 要使您当前的想法发挥作用,您需要为每种类型创建不同的变量并转换为这些变量,或者每次要使用变量时进行转换。 或者尝试将这种类型统一为迈克尔普莱尔建议的那种。 否则你可以试试宏 - 参见下面的例子来实现上述 ...
  • 从你的问题来看,我不能确定你的理解水平,但看起来好像你不熟悉指针的机制,所以我会试着给出一个快速的解释。 您的参数void * app_key是一个整数,用于存储未知(void)类型块的内存中的位置。 您的char *流也是一个整数,它将该位置存储在char类型的块的内存中(单个char或连续块中的第一个char)。 您的代码行char *stream = (char *)app_key复制char *stream = (char *)app_key的整数值(即app_key引用的内存中的地址),并将其存储 ...
  • 问题在于没有一个“方法函数在C中调用工作” - 只有函数调用在特定的C实现上工作的方式。 作为一个具体的例子,调用约定(如x86 stdcall )的“被调用者清理”要求被调用者知道有多少参数被推送到堆栈以执行正确的清理,这在您的示例中将被颠覆。 The problem is that there isn't a single "way function calls work in C" - there's only the way that function calls work on a particu ...
  • 指针类型转换在机器级别上不起任何作用。 内存中的值仍然只是内存中一个普通的旧值。 在语言层面,该值被用作地址。 换句话说,它通常用作传递给需要内存位置的操作的值,例如程序集“加载”操作。 在语言层面,额外的结构被添加到机器操作中,其中一个“额外”是数据类型。 编译器负责检查类型规则是否存在,但运行时不存在这样的约束。 因此,转换在运行时不做任何事情,但是在编译时它会指示编译器不发出错误,因为指针值的类型现在将被视为与持有该地址的变量的兼容类型。 Pointer type casting doesn't do ...
  • 我们说,所显示的代码非常糟糕。 void*与在C ++中破坏类型系统一样接近。 正如评论中所提到的, std::any是一个更好的解决方案。 也就是说,我把它作为一种挑战,以一种类型安全的方式实现你在问题中所说明的内容。 至少可以说,这太过分了。 #include #include using namespace std; template struct is_str_literal : false_type {}; templat ...
  • 正如Mohit所说,是的:输出显示最低有效位在内存中较低的地址,或者“小端是第一个”; 或“小端”。 这可能有些令人困惑,特别是对于从左到右书写和阅读的西方人。 我只能怀疑那些读写希伯来语或阿拉伯语的人不会感到困惑。 其中一个后果是位移操作符在它们所表示的相反“方向”上工作。 关于任一字节顺序的优点和缺点都存在很多争议; 最后它并不重要,当然C的重大成就是从具体的架构中抽象出足以平滑差异并使程序可移植(但不妨碍对位和字节的访问)。 对于小端,有点不直观的是,一个字节中的位仍然是从右到左的上升(我们写它们的方 ...
  • 我通过另一个论坛找到了自己的答案。 关键是在通过CFFTPCreateParsedResourceListing传递CFDictionaryRef时使用&运算符。 例如: CFFTPCreateParsedResourceListing(kCFAllocatorDefault, listingBuffer, bufferLength, ¤tListingRef); I figured out my own answer through another forum. The key is to ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)